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

Created on 28 Jan 2020  路  10Comments  路  Source: microsoft/TypeScript

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

Awaiting More Feedback Suggestion

Most helpful comment

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

All 10 comments

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.

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

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"?

@RyanCavanaugh Can you triage the other issues too?

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

@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?

@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.

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.

your issues are very confusing

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

The聽global Symbol聽properties will聽be聽fixed by聽https://github.com/microsoft/TypeScript/pull/24738, which聽converts聽them all聽to聽unique聽symbol聽types.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manekinekko picture manekinekko  路  3Comments

wmaurer picture wmaurer  路  3Comments

uber5001 picture uber5001  路  3Comments

dlaberge picture dlaberge  路  3Comments

jbondc picture jbondc  路  3Comments