@@ -12,6 +12,7 @@ import {
1212} from '@react-navigation/core'
1313import type { StaticScreenProps } from '@react-navigation/core'
1414import type {
15+ AllOptionalParamRouteKeys ,
1516 NoParamRouteKeys ,
1617 ParamRouteKeys ,
1718 RouteKeys ,
@@ -24,11 +25,13 @@ import {shallowEqual} from './utils'
2425import { registerDebugClear } from '@/util/debug'
2526import { makeUUID } from '@/util/uuid'
2627
27- type IsExactlyRecord < T > = [ T ] extends [ Record < string , unknown > ]
28- ? [ Record < string , unknown > ] extends [ T ]
29- ? true
30- : false
31- : false
28+ // Detects the unconstrained Record<string,unknown> index-signature type.
29+ // We can't use bidirectional assignability ([Record] extends [T] && [T] extends [Record])
30+ // because TypeScript allows Record<string,unknown> to be assigned to any all-optional-property
31+ // type, making the check incorrectly return true for {x?: string} etc.
32+ // Instead, check for an index signature: string extends keyof T is true only for
33+ // Record<string,unknown>-like types (index signatures), not for specific property types.
34+ type IsExactlyRecord < T > = string extends keyof T ? true : false
3235
3336type NavigatorParamsFromProps < P > = P extends Record < string , unknown >
3437 ? IsExactlyRecord < P > extends true
@@ -248,7 +251,7 @@ export const navUpToScreen = (name: RouteKeys) => {
248251 n . dispatch ( StackActions . popTo ( typeof name === 'string' ? name : String ( name ) ) )
249252}
250253
251- export function navigateAppend < RouteName extends NoParamRouteKeys > ( path : RouteName , replace ?: boolean ) : void
254+ export function navigateAppend < RouteName extends NoParamRouteKeys | AllOptionalParamRouteKeys > ( path : RouteName , replace ?: boolean ) : void
252255export function navigateAppend < RouteName extends ParamRouteKeys > (
253256 path : { name : RouteName ; params : KBRootParamList [ RouteName ] } ,
254257 replace ?: boolean
0 commit comments