I'm trying to pass types (screen param types) to a field based on the value (screenName) entered.
This is the navigation prop.
export interface IEditProfileStackNavigatorProps<RouteName extends keyof EditProfileRoutes> { navigation: StackNavigationProp<EditProfileRoutes, RouteName>; route: RouteProp<EditProfileRoutes, RouteName>;}
and the routes
export type EditProfileRoutes = { Options: undefined; Name: undefined; Username: { token: string }; Bio: undefined; Location: undefined; VerifyUser: { screenToNavigateTo: keyof Omit<EditProfileRoutes, 'VerifyUser'> | keyof ManageAccountRoutes; params: any; };};
I would like params to receive param types of a screen based on the screen name inserted in the navigation function.
navigation.navigate('VerifyUser', { screenToNavigateTo: 'Username', params: { some: 'value' } })}
so that if the screen inserted in screenToNavigateTo
is username
the param type will be { token: string }
and for the rest it will be undefined
.
My approach was doing something like
export type EditProfileRoutes = { Options: undefined; Name: undefined; Username: { token: string }; Bio: undefined; Location: undefined; VerifyUser: { screenToNavigateTo: keyof Omit<EditProfileRoutes, 'VerifyUser'> | keyof ManageAccountRoutes; params?:EditProfileRoutes['VerifyUser']['screenToNavigateTo']; };};
but this seems not to work