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
Narrowed types from user defined type guards are lost in subsequent method calls #20186
{// no errorconstarr1: Array<number>=['foo',1].filter((x): x is number=>typeofx==='number',);/* unexpected error:[ts]Type '(string | number)[]' is not assignable to type 'number[]'.Type 'string | number' is not assignable to type 'number'.Type 'string' is not assignable to type 'number'.*/constarr2: Array<number>=['foo',1].filter((x): x is number=>typeofx==='number').map(x=>x);// workaround. no errorconstarr3: Array<number>=['foo',1].filter((x: any): x is number=>typeofx==='number').map(x=>x);}
Activity
trxcllnt commentedon Nov 21, 2017
possibly related to #19334. defining the type-guard predicate before the filter call works fine:
trxcllnt commentedon Nov 21, 2017
Oliver Joseph Ash (@OliverJAsh) based on #19640 (comment) it looks like this may be fixed by #17600, as this form also works in 2.6.1:
ahejlsberg commentedon Dec 3, 2017
This is indeed fixed by #17600.