-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Symbol description property should not forget its value. #56535
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
You’re looking for - const y = sym as (unique symbol & {description:'foo'})
+ const y = sym as (typeof sym & {description:'foo'}) |
@andrewbranch You're right! Adding a wrapper type works. It seems an assertion does as well: const sym = Symbol('foo')
assert(sym.description === 'foo') |
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@andrewbranch why did you mark this as a question? Is there a design reason the auxiliary type or the assertion should be needed at all? |
Yes, this is working as intended; I sometimes use "Question" to indicate that the OP was trying to solve a problem and found a solution, even if they went in thinking they were seeing a bug. |
🔎 Search Terms
symbol, description
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?esModuleInterop=false&declaration=false&target=9&jsx=0&module=7&stripInternal=false&noErrorTruncation=true&ts=5.4.0-dev.20231124&ssl=10&ssc=48&pln=1&pc=1#code/MYewdgzgLgBBCeBbGBeGBlJAjEAbAFAOQBmIIhAlAFBUD0tMUAFgJYQwCGEELA5mIgCmYWBCYgArrgAmMAO4gATgGsqoSLAAeALgDe0wRGCKWABygtw2kmUIBfVHCQ16jVuwUqOiyWFnSQQxgwEFhPVXVoGHhHBGQuGHwJMBYARwlBJ0QcXBgAMhh9Q2MzCysbcjtqOgZmNnklZXYsCVhBRS4guJyYZLSMsEMINXAogC9YpE52fG68fMKDIxNzSzBrUkqKIA
💻 Code
🙁 Actual behavior
The assignment fails with
Typescript infers
sym
as aunique symbol
with areadonly description
property of typestring | undefined
.Note that you can't correct this with an intersection type (as also illustrated in the example)
🙂 Expected behavior
Typescript should infer that
description
is of type"foo"
and permit the assignment.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: