Reputation: 73
Is there some way to specify a "not" type in flow? For example,
compact = (input: Array<any>): Array<notFalsey> => input.filter(i => !!i);
?
Upvotes: 1
Views: 359
Reputation: 1937
Currently, there is no syntax to specify a "not" type, like $Not<string>
, which would be anything but a string.
For your specific compact
example, Flow's library definition for Array.prototype.filter
does include a special case for using the Boolean
function as the filter function. So you can write
const compactedArray = myArray.filter(Boolean);
v0.31.0 will ship with a magic type $NonMaybeType
, so you will be able to write a compact
function with return type Array<$NonMaybeType<T>>
.
Upvotes: 4