Closed
Description
This is a place holder for changes to the type narrowing behavior in TypeScript 2.0:
- Generic type parameters are now narrowed
function g<T>(obj: T) {
var t: T;
if (obj instanceof RegExp) {
t = obj; // RegExp is not assignable to T
}
}
See the explanation by @Arnavion in #7719 (comment)
- Type narrowing does not work for catprued variables in functions and class expressions
export class Class {
constructor(public p) { }
}
var c: Class | string;
var x: Class;
if (c instanceof Class) {
function inner() {
x = c; // Error, type of c is not narrowed, c is Class | string
}
x = c; // OK, c is Class
}