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

unique symbols from the global SymbolConstructor widen way too eagerly #53276

Open
weswigham opened this issue Mar 15, 2023 · 3 comments · May be fixed by #54778
Open

unique symbols from the global SymbolConstructor widen way too eagerly #53276

weswigham opened this issue Mar 15, 2023 · 3 comments · May be fixed by #54778
Labels
Bug A bug in TypeScript Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined
Milestone

Comments

@weswigham
Copy link
Member

Given

const a = Symbol.toStringTag;

class F {
    [a](){ return "" }
}

(new F())[a];

we currently issue a Element implicitly has an 'any' type because expression of type 'symbol' can't be used to index type 'F'.(7053) error on the access.

There should be no errors, as with

const a = Symbol();

class F {
    [a](){ return "" }
}

(new F())[a];

since Symbol.toStringTag is a unique symbol just like what Symbol() makes.

@weswigham weswigham added Bug A bug in TypeScript Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined labels Mar 15, 2023
@fatcerberus
Copy link

fatcerberus commented Mar 15, 2023

Wait, why is a well-known symbol typed as unique symbol? That feels wrong to me.

@weswigham
Copy link
Member Author

weswigham commented Mar 16, 2023

Because it's a specific, unique symbol. As a matter of fact, we don't even have the concept of a "well-known" symbol anymore - unique symbols subsumed them as the more general concept (the term well known no longer appears anywhere in the checker's code, just some old comments!).

@fatcerberus
Copy link

fatcerberus commented Mar 16, 2023

I guess I just always saw unique symbol as this special nominal type that every time it's mentioned, refers to a distinct type, so it feels weird to apply that to values that are predefined by the runtime. IOW unique symbol implies to me a value that can't be forged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Literal Types Unit types including string literal types, numeric literal types, Boolean literals, null, undefined
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants