有没有办法在没有注释A< + T>?
的情况下对此进行建模class A<T> {
static value: T
}
declare var Bar: Class<A<string>>
declare var Baz: Class<A<number>>
function foo<T, U: T>(...rest: $ReadOnlyArray<Class<A<U>>>): Array<T> {
return rest.reduce((init, { value }) => ([ ...init, value ]), [])
}
(foo(Bar, Baz): Array<string | number>)
错误
5: declare var Bar: Class<A<string>>
^ string. This type is incompatible with
6: declare var Baz: Class<A<number>>
^ number
6: declare var Baz: Class<A<number>>
^ number. This type is incompatible with
5: declare var Bar: Class<A<string>>
^ string
答案 0 :(得分:0)
我不是Flow的专家,但我相信你可以通过改变
来实现这一目标$ReadOnlyArray<Class<A<U>>>
到
$ReadOnlyArray<{+value: U}>