Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yortus opened this issue Feb 13, 2018 · 1 comment
Closed

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

yortus opened this issue Feb 13, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@yortus
Copy link
Contributor

yortus commented Feb 13, 2018

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.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2018

Should be fixed by #22339

@mhegazy mhegazy closed this as completed Mar 8, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 8, 2018
@mhegazy mhegazy assigned weswigham and unassigned rbuckton May 1, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants