I am not able to determine the correct type definition for a Stack group with screens (see 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>
);
}
As part of the root stack 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 tried the below (and a few other combinations..)
export type TestStackParamList = {
TestScreen: TestScreenParams;
TestResultScreen: TestScreenParams;
StaticContentScreen: StaticContentParams;
TestModal: RouteGroupConfig<TestStackGroupParamList, NativeStackNavigationOptions>;
};
export type TestStackGroupParamList = {
TestModal: { simplified: string; type: ModalType };
};
I am getting this linter error:
Type '({ children, navigation, route, }: TestModalProps) => ReactNode' is not assignable to type 'ScreenComponentType<TestStackParamList, "TestModal"> | undefined'.
The error is clear, but I am not able to figure out the right "combination" of navigation types.