-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 2.6.1 / 2.7.0-dev20171109
Code
type MapToNum<T> = {
[K in keyof T]?: number|Array<number>;
};
function test<T>(m: MapToNum<T>, k: keyof MapToNum<T>) {
let y = m[k];
let z: number[] = [];
if (y instanceof Array) {
// Works, but y has type any[], should be number[]
z = z.concat(y);
} else if (y) {
// Error, y has type number|number[], should just be number
z.push(y);
}
}Expected behavior: instanceof Array should narrow number|number[]|undefined to number[] and the else if (y) should narrow further to number.
Actual behavior: Narrowed to any[] and number|number[] respectively.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug