Skip to content

Instantly share code, notes, and snippets.

@shk2000v
Created May 28, 2023 08:42
Show Gist options
  • Save shk2000v/3dfbaea17ec735321f7f6392100d4a99 to your computer and use it in GitHub Desktop.
Save shk2000v/3dfbaea17ec735321f7f6392100d4a99 to your computer and use it in GitHub Desktop.
How to write react navigation type
import { NativeStackScreenProps } from '@react-navigation/native-stack';
type StartStackParamList = {
Start: undefined;
Home: undefined;
// .. something
};
type OtherStackParamList = {
OtherScreen: { other : string } | undefined;
AnotherScreen?: { another : string }
}
type StackParamList = StartStackParamList & OtherStackParamList
export type RootStackParamList = {
[key in keyof StackParamList]: StackParamList[key] extends infer Param
? Param extends undefined
? undefined | StackParamList[key]
: StackParamList[key]
: never;
};
export type RootStackScreenProps<Screen extends keyof RootStackParamList> =
NativeStackScreenProps<RootStackParamList, Screen>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment