2017-02-17 3 views
1

Я пишу компонент в React, который ожидает получить компонент, которому принадлежит определенное поле onPropChange, к которому можно получить доступ через ref в качестве опоры.Объявить полиморфный класс, который расширяет другой полиморфный класс

/* @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 как параметры типа. Что я забыл?

ответ