Closed
Description
TypeScript Version: 2.8.3
Code
interface Obj {
}
const obj: Obj = {};
const xs: boolean[] = [false, true, true];
const ys: Array<Obj | null> = [null, obj, obj];
function identity(): undefined;
function identity<T>(x: T): T
function identity(...args: any[]): any {
if (args.length) {
return args[0];
}
}
/**
* Or import {identity} from 'lodash/fp';
*
* Type definition of LodashIdentity is
*
* interface LodashIdentity {
* (): undefined;
* <T>(value: T): T;
* }
*/
xs.filter(identity).map(x => x /* x is still boolean */);
ys.filter(identity).map(y => y /* y is still Obj | null */);
Expected behavior:
x
is inferred as true
.
y
is inferred as Obj
.
Actual behavior:
x
is still boolean
.
y
is still Obj | null
.
Playground Link: Reproduce