I'm having trouble figuring out the proper type definition for a Stack group that includes screens (refer to TestStack.Group
and the nested TestStack.Screen
).
The navigation stack:
const TestStack = createNativeStackNavigator<TestStackParamList>();
function TestNavigator() {
return (
<TestStack.Navigator initialRouteName="TestScreen">
<TestStack.Screen
name="TestScreen"
component={TestScreen}
options={{ headerShown: true, title: "", headerTransparent: true }}
/>
<TestStack.Group screenOptions={{ presentation: "modal" }}>
<TestStack.Screen name="TestModal" component={TestModal} options={{ title: "" }} />
</TestStack.Group>
</TestStack.Navigator>
);
}
Part of the root stack is defined as:
export type RootStackParamList = {
TestStack: NavigatorScreenParams<TestStackParamList> | TestScreenParams;
...
}
export type TestStackParamList = {
TestScreen: TestScreenParams;
TestResultScreen: TestScreenParams;
StaticContentScreen: StaticContentParams;
};
export type TestScreenParams = {
param1: string;
param2: string;
};
I've attempted the following (among other variations..)
export type TestStackParamList = {
TestScreen: TestScreenParams;
TestResultScreen: TestScreenParams;
StaticContentScreen: StaticContentParams;
TestModal: RouteGroupConfig<TestStackGroupParamList, NativeStackNavigationOptions>;
};
export type TestStackGroupParamList = {
TestModal: { simplified: string; type: ModalType };
};
This linter error is being displayed:
Type '({ children, navigation, route, }: TestModalProps) => ReactNode' is not assignable to type 'ScreenComponentType<TestStackParamList, "TestModal"> | undefined'.
The error message is clear, but I am struggling to find the correct "combination" of navigation types.