From eb59bd3d9c729935ca683c3758a75ea082ae7a39 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 28 May 2025 12:18:22 +0300 Subject: [PATCH] =?UTF-8?q?upgrade=20useNavigationDeduped=20(had=20to=20ts?= =?UTF-8?q?-ignore=20=F0=9F=98=AD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/hooks/useNavigationDeduped.ts | 42 +++++++++++++++------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/lib/hooks/useNavigationDeduped.ts b/src/lib/hooks/useNavigationDeduped.ts index 56ae5e8a29..08a8d0c416 100644 --- a/src/lib/hooks/useNavigationDeduped.ts +++ b/src/lib/hooks/useNavigationDeduped.ts @@ -1,10 +1,10 @@ -import React from 'react' +import {useMemo} from 'react' import {useNavigation} from '@react-navigation/core' -import {NavigationState} from '@react-navigation/native' -import type {NavigationAction} from '@react-navigation/routers' +import {type NavigationState} from '@react-navigation/native' +import {type NavigationAction} from '@react-navigation/routers' import {useDedupe} from '#/lib/hooks/useDedupe' -import {AllNavigatorParams, NavigationProp} from '#/lib/routes/types' +import {type AllNavigatorParams, type NavigationProp} from '#/lib/routes/types' export type DebouncedNavigationProp = Pick< NavigationProp, @@ -22,16 +22,19 @@ export function useNavigationDeduped() { const navigation = useNavigation() const dedupe = useDedupe() - return React.useMemo( - (): DebouncedNavigationProp => ({ - // Types from @react-navigation/routers/lib/typescript/src/StackRouter.ts + return useMemo( + () => ({ + // Types from @react-navigation/routers/src/StackRouter.ts push: ( - ...args: undefined extends AllNavigatorParams[RouteName] - ? - | [screen: RouteName] - | [screen: RouteName, params: AllNavigatorParams[RouteName]] - : [screen: RouteName, params: AllNavigatorParams[RouteName]] + ...args: { + [Screen in keyof AllNavigatorParams]: undefined extends AllNavigatorParams[Screen] + ? + | [screen: Screen] + | [screen: Screen, params: AllNavigatorParams[Screen]] + : [screen: Screen, params: AllNavigatorParams[Screen]] + }[RouteName] ) => { + // @ts-expect-error can't get the types to work -sfn dedupe(() => navigation.push(...args)) }, // Types from @react-navigation/core/src/types.tsx @@ -46,14 +49,17 @@ export function useNavigationDeduped() { ) => { dedupe(() => navigation.navigate(...args)) }, - // Types from @react-navigation/routers/lib/typescript/src/StackRouter.ts + // Types from @react-navigation/routers/src/StackRouter.ts replace: ( - ...args: undefined extends AllNavigatorParams[RouteName] - ? - | [screen: RouteName] - | [screen: RouteName, params: AllNavigatorParams[RouteName]] - : [screen: RouteName, params: AllNavigatorParams[RouteName]] + ...args: { + [Screen in keyof AllNavigatorParams]: undefined extends AllNavigatorParams[Screen] + ? + | [screen: Screen] + | [screen: Screen, params: AllNavigatorParams[Screen]] + : [screen: Screen, params: AllNavigatorParams[Screen]] + }[RouteName] ) => { + // @ts-expect-error can't get the types to work -sfn dedupe(() => navigation.replace(...args)) }, dispatch: (