我试图将多态性用于带有遗传的反应组件,但是我看到"这种类型与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>
}
}
链接到游乐场。
我在做什么错?
在github上回答
必须定义类上的状态类型。