有人可以解释一下,当它是对象属性时,为什么 flow 不接受更多限制类型的参数来运行期望更少限制类型的函数?
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgCSAdjgK4ZgC8YA3qmGNvgFxgDOGATgJbEDmAGlQBfANzpmBAPIVylGvUZS2AcgByAQwBuq4SPQBjOMU5gocONTAAKAJRtZGedQB8tpU1x41W3frsJVGNTSgAjTS5rGz55NhJ5Ozc6BjAQ9jgYPAA6eH4bVViKPTAijECwUXQIrhsLOHtAoA
/* @flow */
type Input = {
type: string,
};
type Output = {
type: 'Nav',
}
const foo = (): Output => ({
type: 'Nav',
});
const bar = (input: Input) => {
console.log('input', input);
}
bar(foo());
错误:
19: bar(foo());
^ Cannot call `bar` with `foo()` bound to `input` because string literal `Nav` [1] is incompatible with string [2] in property `type`.
References:
8: type: 'Nav',
^ [1]
4: type: string,
^ [2]
我是否遗漏了文档中的某些内容?
慕桂英4014372
相关分类