How can I type the react-native navigation? I have a stack with nested stack, the typing for the stack is pretty simple but when I try to type the nested I am not able to find a solution.
export enum NestedNavigatorScreens {
Start = 'NestedNavigatorScreens_Start',
Stop = 'NestedNavigatorScreens_Stop',
}
export type RootScreensProps = {
[RootScreens.AppUpdateRequiredScreen]: undefined;
[RootScreens.SignInScreen]: undefined;
// Here I have my nested Navigator which should also get passed some params, but I am not able to find a solution for this how I can give the right type.
[RootScreens.NestedNavigator]: {
screen: NestedNavigatorScreens;
params: // How can I define them for each type individual?
};
}
export const Stack = createStackNavigator<RootScreensProps>();
For Example NestedNavigatorScreens.Start should get params with { currentStep: number, email: boolean }and NestedNavigatorScreens.Stopshould get { currentStep: number, finished: boolean }
I also added a navigation.d.ts to just define the types ones in and not to need to define them on every useNavigation<CustomType>().
import { RootScreensProps } from '@core/presentation/navigation/screens';
declare global {
namespace ReactNavigation {
interface RootParamList extends RootScreensProps {}
}
}