How to define types for shared screens in the react-navigation stack navigators?

Viewed 140

If I have two stack navigators which have the same screen, how can I define typescript types for that screen?

If it belongs in only one navigator I would put something like this:

export interface SharedScreenProps {
  navigation: StackNavigationProp<
    FirstNavigatorParams,
    'Shared screen'
  >;
  route: RouteProp<FirstNavigatorParams, 'Shared screen'>;
}

Both stack navigators have their own routes that this screen can take and they don't have anything in common. Now when I have the second stack navigator I can make the types working. There is CompositeNavigationProp but it isn't that much of a help and it does not suit this use case. Thank you.

0 Answers
Related