有什么方法可以在流程中指定 "not" 类型吗?
Is there some way to specify a "not" type in flow?
有什么方法可以在流程中指定 "not" 类型吗?例如,
compact = (input: Array<any>): Array<notFalsey> => input.filter(i => !!i);
?
目前,没有指定 "not" 类型的语法,例如 $Not<string>
,它不是字符串。
对于您的特定 compact
示例,Array.prototype.filter
的 Flow 库定义确实包含使用 Boolean
函数作为过滤器函数的特殊情况。所以你可以写
const compactedArray = myArray.filter(Boolean);
v0.31.0 将附带魔术类型 $NonMaybeType
,因此您将能够使用 return 类型 Array<$NonMaybeType<T>>
.[=18 编写 compact
函数=]
有什么方法可以在流程中指定 "not" 类型吗?例如,
compact = (input: Array<any>): Array<notFalsey> => input.filter(i => !!i);
?
目前,没有指定 "not" 类型的语法,例如 $Not<string>
,它不是字符串。
对于您的特定 compact
示例,Array.prototype.filter
的 Flow 库定义确实包含使用 Boolean
函数作为过滤器函数的特殊情况。所以你可以写
const compactedArray = myArray.filter(Boolean);
v0.31.0 将附带魔术类型 $NonMaybeType
,因此您将能够使用 return 类型 Array<$NonMaybeType<T>>
.[=18 编写 compact
函数=]