Title: unique symbol lost on assignment to const despite type assertion · Issue #55901 · microsoft/TypeScript · GitHub
Open Graph Title: unique symbol lost on assignment to const despite type assertion · Issue #55901 · microsoft/TypeScript
X Title: unique symbol lost on assignment to const despite type assertion · Issue #55901 · microsoft/TypeScript
Description: 🔎 Search Terms unique symbol widening 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground Link 💻 Code const u = Symbol(); const a7 = u as typeof u // widened to symbol 🙁 Actual be...
Open Graph Description: 🔎 Search Terms unique symbol widening 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground Link 💻 Code const u = Symbol(); const a7 = u as t...
X Description: 🔎 Search Terms unique symbol widening 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground Link 💻 Code const u = Symbol(); const a7 = u ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/55901
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"unique symbol lost on assignment to const despite type assertion ","articleBody":"### 🔎 Search Terms\r\n\r\nunique symbol widening\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground Link](https://www.typescriptlang.org/play?#code/N4KABBYMYPYHYGcAuYCuYC8YBEBBbA3OJLIigIYCMmaY5CYSAngA4CmMAZrQPQ9hwYKAO4BLACZs4bccQilkdAEw10fAULBjJ02ZDAAbNhQDMqug2bsuvfoJESpMuYeN0ALOfXansgL4gIKD6CijoWADKTAC2AEYwBgAUAJREIfCKVOb0jKwc3Gr8PrpggLwbgKU7LqHKXkWOui5GptmWeTaFWvUyZZX6TR61nTrOfkA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nconst u = Symbol();\r\nconst a7 = u as typeof u // widened to symbol\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\n`a7` is `symbol`\r\n\r\n### 🙂 Expected behavior\r\n\r\n`a7` has `typeof u`\r\n\r\n### Additional information about the issue\r\n\r\nThis issue is a huge problem for isolated declarations as it breaks the assumption that in an expression `const o = a as T` we can always use `T` as the type of `o`. This is also inconsistent with the way similar expressions work for string/number literal types ([ex](https://www.typescriptlang.org/play?#code/N4KABBYMYPYHYGcAuYCuYC8YBEBBbA3OJLIigIYCMmaY5CYSAngA4CmMAZrQPQ9hwYKAO4BLACZs4bccQilkdAEw10fAULBjJ02ZDAAbNhQDMqug2bsuvfoJESpMuYeN0ALOfXansgL4gIKD6CijoWADKTAC2AEYwBgAUAJREIfCKVOb0jKwc3Gr8PrpggLwbgKU7LqHKXkWOui5GptmWeTaFWvUyZZX6TR61nTrOfkA))\r\n\r\nSimilar issues: \r\n- https://github.com/microsoft/TypeScript/issues/43657 - Widening on return type not on variable declaration \r\n- https://github.com/microsoft/TypeScript/issues/55361 - Similar, explicitly typed variable is widened \r\n- https://github.com/microsoft/TypeScript/issues/36876 - Widening when assigning from object property (but no assertion)\r\n- https://github.com/microsoft/TypeScript/issues/53276\r\n\r\n@Andarist perhaps https://github.com/microsoft/TypeScript/pull/54778 also fixes this?","author":{"url":"https://github.com/dragomirtitian","@type":"Person","name":"dragomirtitian"},"datePublished":"2023-09-28T09:34:26Z","url":"https://github.com/microsoft/TypeScript/issues/55901"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a215491c-59fb-37e1-8816-31ae4cc59129 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB10:12D34E:6BA5C1:933631:6B047817 |
| html-safe-nonce | e9b5921bd9f1390fadddf5f6f17b8f3f249123f89446e139aa3cdcc9fb4330d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjEwOjEyRDM0RTo2QkE1QzE6OTMzNjMxOjZCMDQ3ODE3IiwidmlzaXRvcl9pZCI6IjY3NTU1NDI4MTMxNTQ1MDY3NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 50f5d42e2a2811671898bf18c62d5bbc319fbff46ffdcae595680bcdb3378e6e |
| hovercard-subject-tag | issue:1917095937 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/55901/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bf18b733d12f922b0595a3ff32589f825d10f62a206470375ec41cbc94616866/microsoft/TypeScript/issues/55901 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bf18b733d12f922b0595a3ff32589f825d10f62a206470375ec41cbc94616866/microsoft/TypeScript/issues/55901 |
| og:image:alt | 🔎 Search Terms unique symbol widening 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground Link 💻 Code const u = Symbol(); const a7 = u as t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dragomirtitian |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cf73f57448d52b3a7b619195e182b33d3b3454ca |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width