4

I have migrated from react-navigation 4.x to 5.x. Since I am using typescript, I am trying to add the types. I should mention that the functionality works perfectly fine. However, I am getting this typescript error:

enter image description here

TS2345: Argument of type '["PaperPlaneDetails", { paperPlane: PaperPlaneInterface; returnRoute: string; }]' is not assignable to parameter of type '["PaperPlaneDetails"] | ["PaperPlaneDetails", undefined]'.   Type '["PaperPlaneDetails", { paperPlane: PaperPlaneInterface; returnRoute: string; }]' is not assignable to type '["PaperPlaneDetails", undefined]'.     Type '{ paperPlane: PaperPlaneInterface; returnRoute: string; }' is not assignable to type 'undefined'.
//OpenPaperPlaneModal.tsx located in ReceivePaperPlaneScreen.tsx

type AppStackParamList = {
  EditProfile: undefined;
  Introduction: undefined;
  PaperPlaneDetails: undefined;
  Logout: undefined;
  DebugScreen: undefined;
  PaperPlane: undefined;
  MyProfileScreen: undefined;
  FollowersScreen: undefined;
  FollowingScreen: undefined;
  UsersProfileScreen: undefined;
  SettingsScreen: undefined;
  CommentsScreen: undefined;
};

type PaperPlaneBottomTabNavigatorParamList = {
  TakePaperPlaneScreen: undefined;
  ReceivePaperPlaneScreen: undefined;
  NotificationScreen: undefined;
};

type OpenPaperPlaneModalNavigationProp = CompositeNavigationProp<
  BottomTabNavigationProp<
    PaperPlaneBottomTabNavigatorParamList,
    'ReceivePaperPlaneScreen'
  >,
  StackNavigationProp<AppStackParamList>
>;

export default function OpenPaperPlaneModal(props) {
  const navigation = useNavigation<OpenPaperPlaneModalNavigationProp>();
  navigation.navigate('PaperPlaneDetails', {
    paperPlane: props.paperPlane,
    returnRoute: 'ReceivePaperPlaneScreen',
  });
}
    "typescript": '3.8.3'
    "@react-navigation/bottom-tabs": "^5.3.1",
    "@react-navigation/native": "^5.2.1",
    "@react-navigation/stack": "^5.2.16",
Kasra
  • 1,959
  • 1
  • 19
  • 29

1 Answers1

0

@kasra I was able to fix my issue. Make sure you don't have have any screens with the same name in both the routes, and paramList.

Graeme Paul
  • 1,143
  • 1
  • 16
  • 30