Closed
Description
TypeScript Version: 2.6.1.
Code
{
// no error
const arr1: Array<number> = ['foo', 1].filter(
(x): x is number => typeof x === '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'.
*/
const arr2: Array<number> = ['foo', 1]
.filter((x): x is number => typeof x === 'number')
.map(x => x);
// workaround. no error
const arr3: Array<number> = ['foo', 1]
.filter((x: any): x is number => typeof x === 'number')
.map(x => x);
}
Related ReactiveX/IxJS#162