【发布时间】:2019-10-25 06:38:21
【问题描述】:
我正在尝试使用谓词函数 (https://flow.org/en/docs/types/functions/#toc-predicate-functions),但它不起作用。
给定以下代码:
/* @flow */
// Some function we need exact types for
const someFunc = (addressLine1: string, city: string, zip: string) => ({})
// Predicate
function checker(addressLine1: ?string, city: ?string, zip: ?string): boolean %checks {
return Boolean(addressLine1 && city && zip)
}
// Logic
const addressLine1: ?string = 'a'
const city: ?string = 'b'
const zip: ?string = 'c'
if(checker(addressLine1, city, zip)){
someFunc(addressLine1, city, zip)
}
阅读文档后,我希望上面的代码没有任何错误,但 Flow 抱怨 addressLine1、city 和 zip 在调用 someFunc() 时可能未定义。
对我做错了什么有任何见解吗?
提前致谢, 丹
【问题讨论】:
标签: javascript flowtype predicate