声明一个扩展另一个多态类别的多态类别



我正在编写一个希望接收一个组件的组件,该组件拥有一个特定字段onPropChange,可以通过REF访问,作为Prop。

/* @flow */
import * as React from 'react';
type onPropChangeObject<Props> = {
    [key: $Keys<Props>]: (newValue: any) => void
}
declare class PropWatchableComponent<DefaultProps, Props: Object, State> 
    extends React.Component<DefaultProps, Props, State> 
{
    onPropChange?: onPropChangeObject<Props>;
}

但是,在最新版本的流(0.39.0)中,类型检查失败了,如下所示

8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ undefined. Did you forget to declare some incompatible instantiation of `DefaultProps`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ some incompatible instantiation of `DefaultProps`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ undefined. Did you forget to declare some incompatible instantiation of `State`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {   ^ some incompatible instantiation of `State`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                        ^ DefaultProps. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                        ^ undefined. Did you forget to declare DefaultProps?
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                                                     ^ State. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
                                                                     ^ undefined. Did you forget to declare State?

所有这些关于未定义的谈论是什么?我显然将DefaultPropsState称为类型参数。我忘记了什么?

请参阅此内容,您应该使用interface而代替'class'。

最新更新