React Native首次使用TypeScript时navigation.navigate报错求助
我首次在React Native中使用TypeScript,调用navigation.navigate()函数时出现TypeScript错误。
相关代码
Navigator.tsx
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
相关产品推荐
相关产品推荐

