refactor: improve TypeScript type safety for router navigation

Replaces generic `any` type casts with specific route pattern types to enhance type checking and prevent invalid navigation paths.

Adds backward compatibility alias for the navigation utility function to maintain existing API contracts while improving code organization.
This commit is contained in:
Uruk
2025-09-29 23:20:30 +02:00
parent f16baeb226
commit 184f639920
2 changed files with 5 additions and 2 deletions

View File

@@ -307,7 +307,7 @@ export const AppleTVCarousel: React.FC<AppleTVCarouselProps> = ({
const navigateToItem = useCallback(
(item: BaseItemDto) => {
const navigation = getItemNavigation(item, "(home)");
router.push(navigation as any);
router.push(navigation as `/(auth)/(tabs)/${string}`);
},
[router],
);

View File

@@ -44,6 +44,9 @@ export const itemRouter = (item: BaseItemDto, from: string) => {
return `/(auth)/(tabs)/${from}/items/page?id=${item.Id}`;
};
// Export alias for backward compatibility
export const getItemNavigation = itemRouter;
export const TouchableItemRouter: React.FC<PropsWithChildren<Props>> = ({
item,
isOffline = false,
@@ -106,7 +109,7 @@ export const TouchableItemRouter: React.FC<PropsWithChildren<Props>> = ({
if (isOffline) {
url += `&offline=true`;
}
router.push(url);
router.push(url as `/(auth)/(tabs)/${string}`);
}}
{...props}
>