- Notifications
You must be signed in to change notification settings - Fork12.9k
Closed
Description
TypeScript Version:
nightly (1.9.0-dev.20160323)
Code
letnumbers:number[]=[1,'2',3,'4'].filter(x=>typeofx!=='string');declarefunctionisNumber(arg:any):arg isnumber;letnumbers2:number[]=[1,'2',3,'4'].filter(isNumber);
Expected behavior:
.filter with a type guard returns an array of the specified type. This would be especially useful with--strictNullChecks
, so we could do something likefoo.map(maybeReturnsNull).filter(x => x != null)....
Actual behavior:
.filter returns an array of the same type, and the twolet
s above are errors.