Skip to content

TS2536: Type 'unique symbol' cannot be used to index type 'T'. #21912

Closed
@yortus

Description

@yortus

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 number

Expected 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 TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions