Issue
Obligatory: apologies if this has been asked before!
I'm working on a React Native project and would like to add a placeholder for the screen name:
type HomeNavProps = BottomTabNavigationProp<
RootStackParamList,
"Home"
>
Ideally, I'd like something more generic like:
type NavProps<T> = BottomTabNavigationProp<
RootStackParamList,
T
>
So I can then use it like:
const { navigate } = useNavigation<NavProps<"Home">>()
Granted I'm not sure how to do it, but when I try the above, I just get:
Type 'T' does not satisfy the constraint 'keyof RootStackParamList'.
For reference, RootStackParamList
is:
type RootStackParamList = {
Home: undefined
Levels: undefined
Map: undefined
MyBadges: undefined
MyImpact: undefined
}
Is something like this possible?
Solution
You need to constrain T
to the correct type. This would be the same type as its expected destination.
In this case I believe that would be: keyof RootStackParamList
type NavProps<T extends keyof RootStackParamList> = BottomTabNavigationProp<
RootStackParamList,
T
>
Answered By - Alex Wayne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.