You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native首次使用TypeScript时navigation.navigate报错求助

React Native + TypeScript 中 navigation.navigate() 类型错误求助

我首次在React Native中使用TypeScript,调用navigation.navigate()函数时出现TypeScript错误。

相关代码

import { createNativeStackNavigator, NativeStackScreenProps } from "@react-navigation/native-stack";
import HomeScreen from "../Screens/HomeScreen";
import SecondScreen from "../Screens/SecondScreen";
import { useSelector } from "react-redux";
import PhoneEntry from "../Screens/Auth/PhoneEntry";
import PhoneVerification from "../Screens/Auth/PhoneVerification";
import { CountryListDataProps } from "../components/CountryCodeModal";
import { FirebaseAuthTypes } from "@react-native-firebase/auth";
import ConfirmationResult = FirebaseAuthTypes;

export type RootStackParamList = {
  "Home": undefined;
  "Login": undefined;
  "PhoneEntry":undefined;
  "PhoneVerification":{phoneNumber:string, selectedCountry:Partial<CountryListDataProps>,verification:ConfirmationResult}
};

const Stack = createNativeStackNavigator<RootStackParamList>();

const CustomStackNavigator = () => {
  const auth = useSelector((state) => state.auth.isLoggedIn);

  return (
    <Stack.Navigator initialRouteName={"Home"} screenOptions={{ headerShown: false }}>
      <Stack.Screen name="Home" component={auth?SecondScreen:HomeScreen} />
      <Stack.Screen name="PhoneEntry" component={PhoneEntry}/>
      <Stack.Screen name="Login" component={SecondScreen} />
      <Stack.Screen name="PhoneVerification" component={PhoneVerification} />
    </Stack.Navigator>
  );
};
export type PhoneVerificationType = NativeStackScreenProps<RootStackParamList,"PhoneVerification">
export type PhoneEntryType = NativeStackScreenProps<RootStackParamList,"PhoneEntry">
export type HomeType = NativeStackScreenProps<RootStackParamList,"Home">

export default CustomStackNavigator;

PhoneVerification.tsx 组件定义

function PhoneVerification({navigation,route}:PhoneVerificationType)

其他组件也采用类似的类型定义,但调用navigation.navigate("PhoneVerification", {相关参数})时,TypeScript提示以下错误:

Argument type "PhoneVerification" is not assignable to parameter type any
Argument type {selectedCountry: CountryListDataProps, phoneNumber: string, verification: ConfirmationResult} is not assignable to parameter type any

我已查阅相关解决方案,但均未解决问题,特此求助。


内容的提问来源于stack exchange,提问作者user16780021

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 08:42:42