react-navigation / react-navigation.github.io

Home of the documentation and other miscellanea
https://reactnavigation.org/
MIT License
313 stars 1.9k forks source link

The documentation on type scripting nested navigation is unclear #960

Open otusweb opened 3 years ago

otusweb commented 3 years ago

Current Behavior

export type RootStackParamList = {
  Home: undefined;
  SignInUpTunnel: undefined;
  'Create Conversation modal': NavigatorScreenParams<EditConversationModalNavigatorParamList>;    <==== typescript error here
};

...
    return 
      <AuthenticatedUserProvider>
        <Stack.Navigator screenOptions={{ headerShown: false }} mode="modal">
          <Stack.Screen name="Home" component={HomeDrawerNavigator} />
          <Stack.Screen name="Create Conversation modal" component={EditConversationModalNavigator} />
        </Stack.Navigator>
      </AuthenticatedUserProvider>

...

export type EditConversationModalNavigatorParamList = RootStackParamList & {
  'Create conversation': { userToInvite: UserConversationStatusCellData | null };
};

...

      navigation.navigate('Create Conversation modal', { screen: 'Create conversation', params: { userToInvite } });

Unfortunately, the documentation on this topic is very thin: https://reactnavigation.org/docs/typescript#type-checking-screens-and-params-in-nested-navigator. Also, the documentation uses a different navigation structure than the documentation for nesting navigators. making it hard to know where to actually put the NavigatorScreenParams and what paramList to give it.

Expected Behavior

I would expect the documentation for the typescripting of a nested navigator to include a full example (with the root navigator and nested navigator) and I would expect it to use the same navigators as the documentation to nest navigator.

How to reproduce

Your Environment

software version
typescript 4.0.7
@react-navigation/native 5.9.3
react-native
expo 40
node 14.6.0
npm or yarn 1.22.10
github-actions[bot] commented 3 years ago

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

otusweb commented 3 years ago

Same issue with latest version