我在使用 TypeScript React Native 应用程序中的 React Navigation 将 prop 添加到页面时遇到问题。我尝试按照https://reactnavigation.org/docs/typescript中的说明进行操作,特别是组织类型部分,并创建了一个 navigationTypes.tsx 文件:
import { NativeStackScreenProps } from "@react-navigation/native-stack";
export type StackParamList = {
Home: undefined;
Admin: undefined;
"Trail Screen": { trailID: number } | undefined;
};
export type StackNativeScreenProps<T extends keyof StackParamList> =
NativeStackScreenProps<StackParamList, T>;
declare global {
namespace ReactNavigation {
interface ParamList extends StackParamList {}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在 Trail Screen 组件中调用的内容:
import { StackNativeScreenProps } from "../interfaces/navigationTypes";
type Props = StackNativeScreenProps<"Trail Screen">;
export default function TrailScreen({ trailID, …Run Code Online (Sandbox Code Playgroud)