gpt4 book ai didi

javascript - Flowtype 多态性不起作用

转载 作者:行者123 更新时间:2023-11-29 23:56:54 25 4
gpt4 key购买 nike

我正在尝试对带有继承的 React 组件使用多态性,但我看到“此类型与 V 的某些不兼容实例化不兼容”错误。

代码如下:

// @flow

import React, { Component } from 'react'

type BaseProps = {
name: string
}

type BaseState<T> = {
error: string,
value: ?T,
}

class Base<Props, V> extends Component<any, BaseProps & Props, BaseState<V>> {
state = {
error: '',
value: null,
}
render() {
return <div>this.props.name</div>
}
}


type ExtendedProps = {
foo: string,
}

class ExtendedBase extends Base<ExtendedProps, string> {
render () {
return <div>this.props.name</div>
}
}

Link to Playground .

我做错了什么?

最佳答案

Answered on github

必须为类的状态定义类型。

关于javascript - Flowtype 多态性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41368428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com