【发布时间】:2018-03-26 23:32:56
【问题描述】:
问题可以demo'd here
我想定义一个可以接受混合类型数组的函数:
function foo(x: Array<mixed>): string {
// ... do something
}
然后我尝试使用一些自定义对象类型的数组来调用它:
type Thing = {
id: string
}
let array : Array<Thing> = [{id: 'hello'}];
foo(array);
...我收到以下错误
Cannot call `foo` with `array` bound to `x` because `Thing` [1] is incompatible with mixed [2] in array element.`
关于mixed 类型有什么我不理解的地方吗?为什么不能使用对象数组作为参数?
【问题讨论】:
-
看起来像一个错误,我提出了一个简化示例的问题。 github.com/facebook/flow/issues/6054
标签: flowtype