类型{someParam:boolean}的参数无法分配给类型的参数' partial< string |布尔值>'

发布于 2025-01-24 21:47:28 字数 880 浏览 3 评论 0原文

当我尝试使用当前生成的类型向导航器屏幕添加一些参数时,我会在标题上提到的错误 请注意,它在其他屏幕上工作,并且在此时,我可以在键入route.params

// Screen is an object of screens name
type RouteType<T extends Object, S extends Screen> = RouteProp<
  {
    [key in S]: T;
  },
  S
>;

export type NavigationInjectedProps<T extends Object, S extends Screen> = {
  navigation: NavigationProp<T>;
  route: RouteType<T, S>;
};

方法的道具

type Props = NavigationInjectedProps<
   params,
  'ExampleComp'
>;

添加到我的组件参数

interface params {
  someParam: boolean;
  someOtherParam: string;
}

时访问它,以设置显示错误显示的参数

export default ExampleComp ({navigation}:Props) {

useEffect(() => {
    navigation.setParams({ someParam : false }); // got error here
  }, [navigation]);

}

...

I m gotting the error mentioned on the title while I m trying to add some params to the navigator screen using the current generated type
note that it's working on other screens and also on this I can access to it when typing route.params

// Screen is an object of screens name
type RouteType<T extends Object, S extends Screen> = RouteProp<
  {
    [key in S]: T;
  },
  S
>;

export type NavigationInjectedProps<T extends Object, S extends Screen> = {
  navigation: NavigationProp<T>;
  route: RouteType<T, S>;
};

the props added to my component

type Props = NavigationInjectedProps<
   params,
  'ExampleComp'
>;

params

interface params {
  someParam: boolean;
  someOtherParam: string;
}

method to set the param where the error is shown

export default ExampleComp ({navigation}:Props) {

useEffect(() => {
    navigation.setParams({ someParam : false }); // got error here
  }, [navigation]);

}

...

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文