TypeScript Version:
nightly (1.9.0-dev.20160323)
Code
letnumbers: number[]=[1,'2',3,'4'].filter(x=>typeofx!=='string');declarefunctionisNumber(arg: any): arg is number;letnumbers2: number[]=[1,'2',3,'4'].filter(isNumber);
Playground
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 like foo.map(maybeReturnsNull).filter(x => x != null)....
Actual behavior:
.filter returns an array of the same type, and the two lets above are errors.
TypeScript Version:
nightly (1.9.0-dev.20160323)
Code
Playground
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 two
lets above are errors.