Skip to content

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

Description

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.

Activity

  1. added
    BugA bug in TypeScript
    Domain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefined
    on Mar 15, 2023
  2. fatcerberus commented on Mar 15, 2023

    @fatcerberus

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

  3. weswigham commented on Mar 16, 2023

    @weswigham
    MemberAuthor

    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!).

  4. fatcerberus commented on Mar 16, 2023

    @fatcerberus

    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

  5. RyanCavanaugh commented on Sep 19, 2026

    @RyanCavanaugh
    Member

    The original example is fixed. With --strict --lib es2015, it produced TS7053 through 5.7.0-dev.20240923 and is clean in 5.7.0-dev.20240924, TypeScript 6.0.3, and current native TypeScript.

    The change is PR #59860, which makes non-literal computed class members participate in the class type rather than being dropped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions