我在这个人的头上靠在墙上 . 我正在尝试将flowtype合并到一些反应项目中 . 在大多数情况下,打字似乎很有效 . 但是,我正在使用一个库(react-jss),它使用HOC将样式表类注入到组件中 . 问题是这个模块没有流程类型,所以它会消除我组件上的任何道具验证,因为我的所有组件都被这个HOC包裹 .
我已经能够根据我看到的一些github isuses添加一些打字,所以至少我知道我从react-jss HOC获得了一个组件,但这个新组件没有与它相关的道具从流程的角度来看查看,所以我没有因为未能提供错误类型所需的道具或道具而获得错误(消除了很多流程的好处) . 这是我复制粘贴以获得基本react-jss HOC定义的内容:
declare type FunctionComponent<A> = (props: A) => ?React$Element<any>;
declare type ClassComponent<D, A, S> = Class<React$Component<D, A, S>>;
declare type Component<A> = FunctionComponent<A> | ClassComponent<any, A, any>;
declare type Fn1<A, B> = (a: A) => B;
declare type HOC<A, B> = Fn1<Component<A>, Component<B>>;
declare module 'react-jss' {
declare module.exports: (styleSheet: Object) => HOC<A, B>;
}
请记住react-jss默认导出(injectStyles)的rought签名是这样的:
function injectStyles(styleSheet: AnObject)(Component: ReactComponent<Props>): ReactComponent<PropsWithStyleClasses>
1 回答
您可以尝试以下定义:
请注意,导入注入的组件时,流会出现一些问题 . 使用课程时一切正常:
但是对于功能组件,您需要显式键入它:
我不确定这些问题是否已在流程中修复,但此设置对我来说很好 .