You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If x : T is already known, any bool implies/is evidence for x is T.
This should help type inference for e.g.
function f<T, R extends T>(x: T[], p: (x: T) => x is R): R | undefined {
for (const v of x) {
if(p(v)){return v}
}
}
// doesn't work
f([2,3,4], (x) => x > 3)
// works
f([2,3,4], (x): x is number => x > 3)
(filter, etc)
The text was updated successfully, but these errors were encountered:
acertain
changed the title
given x : T, bool should be a subtype of x is T
given x : T, bool should be a subtype of x is T
Oct 29, 2017
There's no type guard for us to infer in the not-working case. x > 3 isn't correctly of type x is number, because 2 is a number but it would return false. When you explicitly annotate a type predicate we trust you and allow it, but inferring one in this case would be wrong.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
If
x : T
is already known, anybool
implies/is evidence forx is T
.This should help type inference for e.g.
(filter, etc)
The text was updated successfully, but these errors were encountered: