-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
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'.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created