首页 > 解决方案 > 如何在 react-navigation v6 中覆盖全局 RootParamList

问题描述

在 react-navigation v6 的升级指南中:

https://reactnavigation.org/docs/upgrading-from-5.x/#ability-to-specify-a-type-for-root-navigator-when-using-typescript

它声明您可以使用

declare global {
  namespace ReactNavigation {
    interface RootParamList extends RootStackParamList {}
  }
}

在代码中的某处为所有钩子等全局设置 RootParamList。

但是,当我尝试包含该片段并设置我的参数列表时,我得到的只是

Duplicate identifier 'RootParamList'.ts(2300)
types.d.ts(5, 19): 'RootParamList' was also declared here

显然,该类型已经声明,我正在尝试覆盖它,但这似乎是不可能的。

任何想法如何覆盖而不导致类型错误?

标签: react-navigationreact-navigation-v6

解决方案


推荐阅读