Javascript 如何将流与外部高阶组件包装器一起使用
仅显示如何声明自定义高阶组件以使用自定义类及其道具。在我的例子中,我有一个自定义类,如:Javascript 如何将流与外部高阶组件包装器一起使用,javascript,react-native,react-navigation,flowtype,Javascript,React Native,React Navigation,Flowtype,仅显示如何声明自定义高阶组件以使用自定义类及其道具。在我的例子中,我有一个自定义类,如: type Props = { navigation: Object, isFocused: boolean } type State = { config: AppConfig, pack: Package, init: boolean, } class MainAppScreen extends React.Component<Props, State> { ... }
type Props = {
navigation: Object,
isFocused: boolean
}
type State = {
config: AppConfig,
pack: Package,
init: boolean,
}
class MainAppScreen extends React.Component<Props, State> {
...
}
export default withNavigationFocus(MainAppScreen);
当我尝试导入它时,如:()
我得到一个错误:
Error:(22, 14) Cannot import the value `withNavigationFocus` as a type. `import type` only works on type exports like type aliases, interfaces, and classes. If you intended to import the type of a value use `import typeof` instead.
如果我尝试使用typeof,我会得到:
import typeof {withNavigationFocus} from 'react-navigation';
我得到了错误:
Error:(22, 16) Cannot declare `withNavigationFocus` [1] because the name is already bound.
Error:(112, 16) Cannot call `withNavigationFocus` because Named import from module `react-navigation` [1] is not a function.
Error:(112, 16) Cannot build a typed interface for this module. You should annotate the exports of this module with types. Cannot determine the type of this call expression. Please provide an annotation, e.g., by adding a type cast around this expression. (`signature-verification-failure`)
谢谢。Flow抱怨以导航为中心的
未键入。幸运的是,流类型的
项目已经完成。(对于不同版本的react navigation
或flow
,还有其他定义文件;我链接的是react navigation^4.0.0
和flow^0.114.0
)您可以在项目中包含库定义(基本上,只需将文件保存在/flow typed
目录中).使用NavigationFocus
的类型是什么?我说不出来,API参考并不是很具体:您的“当我尝试像这样导入它时”和“如果我尝试使用typeof”的代码示例是相同的;它们都有typeof
。这只是一个复制粘贴错误,还是您忘记尝试从“react navigation”导入{withNavigationFocus}代码>?还请注意,您正在尝试使用导航焦点导入,但前面引用的声明是针对使用导航
,这是一个不同的函数<代码>使用导航焦点
不过。@RoryO'Kane观察得很好,这里只是复制和浪费。我会更新问题的,谢谢!谢谢,这正是缺少的链接。实际上它看起来是正确的解决方案,但它不适用于特殊功能,我更新了问题,也许我用错了?不确定在哪里放置此更新的最佳位置是。。。在任何情况下,都不需要使用NavigationFocus导入类型。流将自动知道使用导航焦点查看声明类型
,因为声明模块'react navigation'
行对应于'react navigation'
中的导入语句import{withNavigationFocus}。
import typeof {withNavigationFocus} from 'react-navigation';
Error:(22, 16) Cannot declare `withNavigationFocus` [1] because the name is already bound.
Error:(112, 16) Cannot call `withNavigationFocus` because Named import from module `react-navigation` [1] is not a function.
Error:(112, 16) Cannot build a typed interface for this module. You should annotate the exports of this module with types. Cannot determine the type of this call expression. Please provide an annotation, e.g., by adding a type cast around this expression. (`signature-verification-failure`)