镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Can't use aliases of the global Symbol value to refer to its properties in the same manner or create unique symbols #36468

Description

Although Nodejs also uses this technique, we can't do the same thing.

https://github.com/nodejs/node/search?q=primordials+symbol&unscoped_q=primordials+symbol

TypeScript Version: 3.7.x-dev.20200125

Search Terms:

Code

export { }
const Symbol = globalThis.Symbol;
const sym = Symbol();
[][Symbol.iterator];

Expected behavior:

const sym = Symbol(); // typeof sym
[][Symbol.iterator]; // Refer iterator method

Actual behavior:

const sym = Symbol(); // symbol
[][Symbol.iterator]; // error

Playground Link: http://www.typescriptlang.org/play/index.html?target=5&ts=3.8.0-dev.20200125&ssl=1&ssc=1&pln=2&pc=21#code/KYDwDg9gTgLgBAbzgXwFAGMIDsDO8DKAngLYBGEANnALxwDmFEpAhhQCoAWAljgHRFlKAbgzY8cHCRpwB5CgAoAlCIDaAXRWzKvLjGBRmMaGqA

Related Issues: #21603 #35478

Activity

  1. falsandtru commented on Jan 28, 2020

    @falsandtru
    ContributorAuthor

    Global variable reference greatly decreases the performance.

    https://falsandtru.github.io/benchmark/suites/10/

    But we can't avoid this performance problem with Symbol caused by global reference because of this issue.

  2. RyanCavanaugh commented on Jan 29, 2020

    @RyanCavanaugh
    Member

    I don't quite understand what you're doing or why, or why what you're doing doesn't justify a type assertion

  3. falsandtru commented on Jan 29, 2020

    @falsandtru
    ContributorAuthor

    what you're doing or why

    To improve runtime performance as I explained above.

    why what you're doing doesn't justify a type assertion

    I'm not sure what you mean. What is meant by "justify a type assertion"?

  4. falsandtru commented on Jan 31, 2020

    @falsandtru
    ContributorAuthor

    Ryan Cavanaugh (@RyanCavanaugh) Can you triage the other issues too?

  5. RyanCavanaugh commented on Jan 31, 2020

    @RyanCavanaugh
    Member

    falsandtru (@falsandtru) if you can come cook dinner and tend to my kid I can work evenings

  6. added
    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this feature
    SuggestionAn idea for TypeScript
    and removed
    Needs More InfoThe issue still hasn't been fully clarified
    on Jan 31, 2020
  7. changed the title [-]Aliased Symbol doesn't work[/-] [+]Can't use aliases of the global `Symbol` value to refer to its properties in the same manner[/+] on Jan 31, 2020
  8. falsandtru commented on Jan 31, 2020

    @falsandtru
    ContributorAuthor

    Ryan Cavanaugh (@RyanCavanaugh) I'm not saying do it right now and the oldest issue in these days (#35896) was opened a month ago. Do you require me to wait more? 2 months?

  9. RyanCavanaugh commented on Jan 31, 2020

    @RyanCavanaugh
    Member

    falsandtru (@falsandtru) your issues are very confusing and require a lot of time to try to piece together what you mean and what you want to happen. You'll have to forgive me that I take up more actionable issues first; other people have put in the work to make understandable reports and are treated as such.

  10. falsandtru commented on Jan 31, 2020

    @falsandtru
    ContributorAuthor

    Can't use aliases of the global Symbol value to refer to its properties in the same manner

    And can't make unique symbols using an alias of the Symbol function. Don't miss it.

  11. changed the title [-]Can't use aliases of the global `Symbol` value to refer to its properties in the same manner[/-] [+]Can't use aliases of the global `Symbol` value to refer to its properties in the same manner or create unique symbols[/+] on Jan 31, 2020
  12. falsandtru commented on Jan 31, 2020

    @falsandtru
    ContributorAuthor

    your issues are very confusing

    Can you point out where I don't know? It is difficult to know it myself.

  13. ExE-Boss commented on Mar 15, 2020

    @ExE-Boss
    Contributor

    The global Symbol properties will be fixed by #24738 #42543, which converts them all to unique symbol types.

  14. bordoley commented on Mar 15, 2023

    @bordoley

    One unfortunate side-effect of the inability to alias the Symbol constructor when defining unique symbol property keys for classes and objects is that it results in increased bundle size, even when compiled with terser (see: terser/terser#1337). Your compiled code becomes littered with Symbol() invocations.

    Typically in libraries one will alias globals like Math to a local variable to work around terser failing to mangle built-ins, but given this TS limitation there is no way for one to do so.

  15. RyanCavanaugh commented on Mar 15, 2023

    @RyanCavanaugh
    Member

    The issue in the OP now behaves as desired, so I'm inclined to close this. Dave (@bordoley) can you confirm or provide a failing repro?

  16. bordoley commented on Mar 15, 2023

    @bordoley

    Ryan Cavanaugh (@RyanCavanaugh): I'll create a test repo, and file a new issue with an example that illustrates the issue.

  17. RyanCavanaugh commented on Mar 15, 2023

    @RyanCavanaugh
    Member

    Thanks!

  18. bordoley commented on Mar 16, 2023

    @bordoley

    see: #53282

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

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions