-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cannot create a unique symbol at each function call #40106
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
Comments
There are two valid interpretations of what this means:
It's not really obvious how you would reason about the second one, since there's not any tracking of any sort of "This symbol came from this invocation" or a way to talk about that in a type syntax position. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh |
This already happens magically when you assign the value returned from |
Search Terms
Symbol, unique, generated, function call
Suggestion
With two functions returning
unique symbol
.When comparing the symbol types when calling these two functions, we get a (correct) error from the compiler telling us that these types are incompatible.
If we call the same function two times though, the types are the same.
I understand that this can be expected in some cases, though there is currently no way to tell the compiler to generate a different unique symbol for each function call.
Use Cases
My current use-case is for creating two objects using the same constructor, that are structurally identical, but that would not be compatible between them (kind of opaque types).
Maybe this should be through the usage of a new keyword to prevent compatibility issues with existing codebases.
Examples
https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXxilWBwFsBlAT1ICMcIAKASgC54BvAkKE1CS+FmBs0WAI7IEAZ2p0I8AL4BuAFChIsBCnTY8BIiQqz6AJmZtOcHnn6Dh8UROnH5ylSvYr48MHikZ4KHgAXn1iMipaemZVb19Uf3gaELDDSLkzJlUvQIA6IRDg0Kh84Fi8gqLQmlKleAB6evgAeQBpFQV3Tzi-AKDQwnCjKMYsnPjE5IGDCJcY928SyqKKspyl4ELq2oamgEl4AHccZAhNkAAPAAdwAIwACxApBAxj+AxKG6l3nCSEYCwiEQIDgqDuOBwHRUQA
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: