我在React中编写一个组件,希望接收一个组件,该组件拥有一个特定字段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>;
}
但是最新版本的Flow(0.39.0)as seen here
中的类型检查失败并出现多个错误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?
所有关于undefined的讨论是什么?我明确声明DefaultProps
和State
作为类型参数。我忘记了什么?