Closed
Description
TypeScript Version: 2.0.2
Code
function bug<T>(obj: T): T {
if (obj instanceof RegExp) {
return obj;
}
return null;
}
function isArray<T>(arg: any): arg is Array<T> {
return true;
}
function bug2() {
let rules: any;
if (isArray(rules)) {
let str: string = rules[0];
}
}
function bug3() {
let values: any[];
let strings: string[];
if (isArray(values)) {
strings = values;
}
}
All this code worked in 1.8.10 but now fails in 2.0.2. From what I can read into the error message the taken type when no actual type parameter is provided is now {}. It seemed to was any before. If I change the code to for example
function bug2() {
let rules: any;
if (isArray<any>(rules)) {
let str: string = rules[0];
}
}
Everything compiles.