请考虑以下简单代码:
/* @flow */
type A = {|
value: {id: number} | number,
value2: string,
|}
type B = {
...$Exact<A>,
value: number,
}
function foo(b:B, add: number) {
console.log(b.value + add);
console.log(b.value2)
}
const v: A = {
value: 2,
value2: 'a',
}
if (typeof v.value === 'number') {
foo(v);
}
typeof
应该指示类型已精炼为“数字”,因此它可以是foo
的参数。但是,当我测试此in a fiddle时,显示了错误。 (Cannot call
foo with
v bound to
b because object type [1] is incompatible with number [2] in property
值.
)