Open psimk opened 3 years ago
but I imagine that this improvement could be added to most if not all predicates Definitely not "all", since there are some explicit return types that are fairly strict.
But even things like either('foo', 'bar')
that normally narrows from unknown
to 'foo' | 'bar'
could benefit if the input is already typed as 'foo'
, to just return 'foo'
?
So I like this approach.
Currently the
value
argument for predicates is hardcoded to beunknown
. This is fine for simple use cases like using predicates in if statements example :arrow_down:However, using predicates in methods and functions which use generics, TS can't correctly infer the type from the predicate.
From what I can gather, making the
value
argument a generic fixes the aboveTS playground
This example is only for
isSome
, but I imagine that this improvement could be added to most if not all predicates.