Closed
Description
TypeScript Version: 2.0.3
Code
// A *self-contained* demonstration of the problem follows...
function testFunction(x: string | Function): any {
if (typeof x === 'string') {
return {
key: function (a: any, b: any) {
// Fine, x is string
return a[x];
}
};
return {
key(a: any, b: any) {
// Fails, x is string | Function here
return a[x];
}
};
}
}
Expected behavior:
Compiles fine
Actual behavior:
Error: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'.