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
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.)
The text was updated successfully, but these errors were encountered:
TypeScript Version: nightly (2.5.0-dev.20170725)
Code
Expected behavior:
No error.
Actual behavior:
Depending on the order I hover over things, hovering over
tryCast
andy
might show a type ofstring | number | undefined
, but it might show a type ofnumber | undefined
. (But the error atz
is always present.)The text was updated successfully, but these errors were encountered: