-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.7.0-dev.20171118
Code
I was expecting this to work after #15473 was merged:
const mySymbol = Symbol('My Symbol');
interface TypeA {
[mySymbol]: Function; // OK
[x: number]: number;
}
interface TypeB {
[mySymbol]: Function; // ERROR: Property '[mySymbol]' is not assignable to string index type
[x: string]: string;
}
let a: TypeA, b: TypeB;
let a1 = a[mySymbol]; // a1 has type Function
let a2 = a[42]; // a2 has type number
let b1 = b[mySymbol]; // b1 has type Function
let b2 = b['foo']; // b2 has type string
Expected behavior:
No compiler errors. mySymbol
is a unique symbol as per #15473 and should not overlap either numeric index types or string index types.
Actual behavior:
Error in TypeB
as shown in the code above. TSC rejects the unique symbol key because it is not compatible with the string index type, even though it is not a string property key.
Note that the types of a1
, a2
, b1
and b2
are all inferred correctly despite the compile error.
aluanhaddad and lukasnagl
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue