首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >声明一个扩展另一个多态类的多态类

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

Stack Overflow用户
提问于 2017-02-18 02:34:50
回答 1查看 366关注 0票数 1

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

代码语言:javascript
复制
/* @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中,类型检查失败并出现多个错误

代码语言:javascript
复制
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都声明为类型参数。我忘了什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42305131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档