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
{{ message }}
Repository navigation
Strange stateful behavior with inferred type predicate type #17451
functiontryCast<T,UextendsT>(value: T,predicate: (t: T)=>t is U): U|undefined{returnpredicate(value) ? value : undefined;}declareconstsn: string|number;constx: number|undefined=tryCast(sn,(n): n is number=>typeofn==="number");// Always worksconsty=tryCast(sn,(n): n is number=>typeofn==="number");constz: number|undefined=y;
Expected behavior:
No error.
Actual behavior:
src/a.ts(11,7): error TS2322: Type 'string | number | undefined' is not assignable to type 'number | undefined'.
Type 'string' is not assignable to type 'number | undefined'.
Depending on the order I hover over things, hovering over tryCast and y might show a type of string | number | undefined, but it might show a type of number | undefined. (But the error at z is always present.)
Activity