小编Chi*_*hip的帖子

反应导航/本机属性在类型道具上不存在

我在使用 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)

typescript react-native react-navigation expo

5
推荐指数
1
解决办法
4240
查看次数

标签 统计

expo ×1

react-native ×1

react-navigation ×1

typescript ×1