我正在尝试在React类上键入一个静态属性,以便在更高阶的组件中使用它类型安全。
My React类定义如下所示:
type ReactComponentClass<DP, P, S> =
| Class<React$Component<DP, P, S>>
| ((props: P) => ?React$Element<any>);
我的第一次尝试是
type ComponentClassWithStaticPropery<DP,P,S> = ReactComponentClass<DP, P, S> & {
staticProp: boolean,
}
这样就失败了:
71: <Component
^ React element `Component`. Expected React component instead of any member of intersection type
54: return ({ Component, ...outerProps }: Props): React$Element<*> => (
^^^^^^^^^ intersection
Member 1:
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type application of polymorphic type: type `ReactComponentClass`
Error:
56: Container={Component}
^^^^^^^^^ intersection. This type is incompatible with
8: | ((props: P) => ?React$Element<any>);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type
Member 1:
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type application of polymorphic type: type `ReactComponentClass`
Error:
8: | ((props: P) => ?React$Element<any>);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. Callable signature not found in
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ statics of React$Component
Member 2:
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^ object type
Error:
8: | ((props: P) => ?React$Element<any>);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function type. Callable signature not found in
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^ object type
Member 2:
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^ object type
Error:
71: <Component
^ React element `Component`. Expected React component instead of
11: type RelayContainer = ReactComponentClass<*, *, *> & {
^ object type