react-navigation 5.x:TS2345:类型'...'的参数不能分配给类型'...'的参数

时间:2020-05-17 09:26:41

标签: reactjs typescript react-native react-navigation react-navigation-v5

我已经从反应导航 4.x 迁移到了 5.x 。由于我正在使用 typescript ,因此我尝试添加类型。我应该提到的是,该功能运行良好。但是,我收到此打字稿错误:

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",

1 个答案:

答案 0 :(得分:0)

@kasra我能够解决我的问题。确保在路由和paramList中都没有同名的屏幕。