Here, result is inferred as string | number (previously if would fail to typecheck, with the error "number" is not assignable to "string". I could see an argument either way, but I think it provides the most convenience, while not suffering any type-safety.
The issue
Currently the inference is not quite great in pipes:
Here,
result
is inferred asunknown
, where is should be at leaststring
.The solution
A potential solution is to compute the return type with a mapped type:
and now the match infers as you would expect:
Here,
result
infers asstring
.Another consequence of this approach is that it's easy to sneak in different return types:
Here,
result
is inferred asstring | number
(previously if would fail to typecheck, with the error"number" is not assignable to "string"
. I could see an argument either way, but I think it provides the most convenience, while not suffering any type-safety.