-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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.8.0-dev.20180211
Search Terms:
- "TS2536"
- "Type 'unique symbol' cannot be used"
Code
const STR = 'a string literal';
const SYM = Symbol('a unique symbol');
const value = {
[STR]: 'foo',
[SYM]: 42,
};
type TypeOfStr<T extends { [STR]: any; }> = T[typeof STR]; // OK
type TypeOfSym<T extends { [SYM]: any; }> = T[typeof SYM]; // ERROR
// ^^^^^^^^^^^
// Type 'unique symbol' cannot be used to index type 'T'
type T1 = TypeOfStr<typeof value>; // T1 is string
type T2 = TypeOfSym<typeof value>; // T2 is numberExpected behavior:
No errors. If it works for string literal types, it seems it should also work for unique symbol types.
Actual behavior:
TS2536 error with unique symbol as shown above. But the type is still correctly inferred on the last line.
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