Title: Make Symbol.* (e.g. Symbol.iterator) unique symbols · Issue #27525 · microsoft/TypeScript · GitHub
Open Graph Title: Make Symbol.* (e.g. Symbol.iterator) unique symbols · Issue #27525 · microsoft/TypeScript
X Title: Make Symbol.* (e.g. Symbol.iterator) unique symbols · Issue #27525 · microsoft/TypeScript
Description: Search Terms Suggestion Use this: declare function Symbol (x?: string | number): symbol declare namespace Symbol { const prototype: symbol const iterator: unique symbol } Or this: interface SymbolConstructor { (x?: string | number): symb...
Open Graph Description: Search Terms Suggestion Use this: declare function Symbol (x?: string | number): symbol declare namespace Symbol { const prototype: symbol const iterator: unique symbol } Or this: interface SymbolC...
X Description: Search Terms Suggestion Use this: declare function Symbol (x?: string | number): symbol declare namespace Symbol { const prototype: symbol const iterator: unique symbol } Or this: interface SymbolC...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27525
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make Symbol.* (e.g. Symbol.iterator) unique symbols","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please read the FAQ first, especially the \"Common Feature Requests\" section.\r\n\r\n-->\r\n\r\n## Search Terms\r\n\r\n\u003c!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->\r\n\r\n## Suggestion\r\n\r\nUse this:\r\n\r\n```typescript\r\ndeclare function Symbol (x?: string | number): symbol\r\n\r\ndeclare namespace Symbol {\r\n const prototype: symbol\r\n const iterator: unique symbol\r\n}\r\n```\r\n\r\nOr this:\r\n\r\n```typescript\r\ninterface SymbolConstructor {\r\n (x?: string | number): symbol\r\n readonly prototype: symbol\r\n readonly iterator: unique symbol\r\n}\r\n\r\ndeclare var Symbol: SymbolConstructor\r\n```\r\n\r\nInstead of this:\r\n\r\n```typescript\r\ninterface SymbolConstructor {\r\n (x?: string | number): symbol\r\n readonly prototype: symbol\r\n readonly iterator: symbol\r\n}\r\n\r\ndeclare var Symbol: SymbolConstructor\r\n```\r\n\r\n## Use Cases\r\n\r\nRight now, I can do this for custom `unique symbol`:\r\n\r\n```typescript\r\nconst foo = Symbol() // unique symbol\r\nconst bar: typeof foo = foo\r\n\r\nconst baz: {\r\n\t[foo]: number\r\n} = {\r\n\t[bar]: 123\r\n}\r\n```\r\n\r\nBut not for `Symbol.*`\r\n\r\n```typescript\r\n// Expecting 'typeof Symbol.iterator' but received 'symbol'\r\nconst iterator: typeof Symbol.iterator = Symbol.iterator\r\n\r\n// This is not working\r\nconst iterable: Iterable\u003cnumber> = {\r\n * [iterator] () {\r\n yield * [0, 1, 2, 3]\r\n }\r\n}\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [x] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n---\r\n\r\n[Playground Link](https://www.typescriptlang.org/play/#src=declare%20function%20FakeSymbol%20()%3A%20symbol%0D%0A%0D%0Adeclare%20namespace%20FakeSymbol%20%7B%0D%0A%20%20const%20prototype%3A%20symbol%0D%0A%20%20const%20iterator%3A%20unique%20symbol%0D%0A%7D%0D%0A%0D%0Aconst%20iterator%3A%20typeof%20FakeSymbol.iterator%20%3D%20FakeSymbol.iterator%0D%0A%0D%0Aconst%20foo%3A%20%7B%0D%0A%20%20%5BFakeSymbol.iterator%5D%3A%20number%0D%0A%7D%20%3D%20%7B%0D%0A%20%20%5Biterator%5D%3A%20123%0D%0A%7D%0D%0A) ([This](https://www.typescriptlang.org/play/#src=interface%20FakeSymbolConstructor%20%7B%0D%0A%20%20(x%3F%3A%20number%20%7C%20string)%3A%20symbol%0D%0A%20%20readonly%20prototype%3A%20symbol%0D%0A%20%20readonly%20iterator%3A%20unique%20symbol%0D%0A%7D%0D%0A%0D%0Adeclare%20const%20FakeSymbol%3A%20FakeSymbolConstructor%0D%0A%0D%0Aconst%20iterator%3A%20typeof%20FakeSymbol.iterator%20%3D%20FakeSymbol.iterator%0D%0A%0D%0Aconst%20foo%3A%20%7B%0D%0A%20%20%5BFakeSymbol.iterator%5D%3A%20number%0D%0A%7D%20%3D%20%7B%0D%0A%20%20%5Biterator%5D%3A%20123%0D%0A%7D%0D%0A) also works)\r\n\r\n[Related Issue](https://github.com/Microsoft/TypeScript/issues/27524)","author":{"url":"https://github.com/KSXGitHub","@type":"Person","name":"KSXGitHub"},"datePublished":"2018-10-03T12:18:01Z","url":"https://github.com/microsoft/TypeScript/issues/27525"}
| 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:0b057d58-4d12-eca7-14fc-17c083ca1a90 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C50C:34B9D4:6BE6E8:991993:6B04704C |
| html-safe-nonce | 64be848374784061f96c91aadc0ec941fe7bda8a554b86ba43645d3acd9f0c06 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTBDOjM0QjlENDo2QkU2RTg6OTkxOTkzOjZCMDQ3MDRDIiwidmlzaXRvcl9pZCI6IjI4MTQ5ODg5NzE3ODk4MDQyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0a60388e6ee7a333b54742b7461ba00ee059d2b6a5c980aa4521ea0cb2a4a0d3 |
| hovercard-subject-tag | issue:366311416 |
| 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/27525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65e994f551f1e9dbf69844be696ef2a56f18c1072f367f6d78b951df8b0e8025/microsoft/TypeScript/issues/27525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65e994f551f1e9dbf69844be696ef2a56f18c1072f367f6d78b951df8b0e8025/microsoft/TypeScript/issues/27525 |
| og:image:alt | Search Terms Suggestion Use this: declare function Symbol (x?: string | number): symbol declare namespace Symbol { const prototype: symbol const iterator: unique symbol } Or this: interface SymbolC... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KSXGitHub |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| 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