我正在用React编写一个组件,它希望接收一个组件,该组件拥有一个可以通过引用访问的特定字段onPropChange,作为一个属性。
/* @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?所有这些关于未定义的讨论是什么?我明确地将DefaultProps和State都声明为类型参数。我忘了什么?
发布于 2017-02-18 06:53:05
https://stackoverflow.com/questions/42305131
复制相似问题