Title: Allow functions to have `new symbol` as the return type · Issue #37469 · microsoft/TypeScript · GitHub
Open Graph Title: Allow functions to have `new symbol` as the return type · Issue #37469 · microsoft/TypeScript
X Title: Allow functions to have `new symbol` as the return type · Issue #37469 · microsoft/TypeScript
Description: Search Terms unique symbol new unique symbol new symbol Suggestion I request that unique symbol be allowed as the return type of a function declaration. Alternatively, it might be better to use new symbol to disambiguate #40106 (comment)...
Open Graph Description: Search Terms unique symbol new unique symbol new symbol Suggestion I request that unique symbol be allowed as the return type of a function declaration. Alternatively, it might be better to use new...
X Description: Search Terms unique symbol new unique symbol new symbol Suggestion I request that unique symbol be allowed as the return type of a function declaration. Alternatively, it might be better to use new...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37469
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow functions to have `new symbol` as the return type","articleBody":"## Search Terms\r\n\r\n- unique symbol\r\n- new unique symbol\r\n- new symbol\r\n\r\n## Suggestion\r\n\r\nI request that `unique symbol` be allowed as the return type of a function declaration.\r\n\r\nAlternatively, it might be better to use `new symbol` to disambiguate \u003chttps://github.com/microsoft/TypeScript/issues/40106#issuecomment-677741032>.\r\n\r\n## Use Cases\r\n\r\nCurrently, it’s impossible to create an alias or a wrapper function for the global `Symbol` constructor and use that to construct unique symbols:\r\n\r\n```js\r\n// ./es-globals/fundamentals.js\r\nexport const ESSymbol = Symbol;\r\nexport const { for: ESSymbol_for } = ESSymbol;\r\n```\r\n```ts\r\n// ./es-globals/fundamentals.d.ts\r\nexport import ESSymbol = globalThis.Symbol;\r\nexport declare const ESSymbol_for: typeof ESSymbol.for;\r\n```\r\n\r\n```js\r\n// ./symbols.js\r\nimport { ESSymbol, ESSymbol_for } from \"./es-globals/fundamentals.js\";\r\n\r\n// should be `unique symbol`, but is instead `symbol`:\r\nexport const customSymbol = ESSymbol(\"custom\");\r\n\r\n// should be `unique symbol` or `global symbol \"nodejs.util.inspect.custom\"`,\r\n// but is instead `symbol`:\r\nexport const nodejs_util_inspect_custom = ESSymbol_for(\"nodejs.util.inspect.custom\");\r\n\r\n// should be `unique symbol` or `global symbol \"nodejs.util.promisify.custom\"`,\r\n// but is instead `symbol`:\r\nexport const nodejs_util_promisify_custom = ESSymbol_for(\"nodejs.util.promisify.custom\");\r\n```\r\n\r\n## Examples\r\n\r\nThis would allow defining `SymbolConstructor` as:\r\n\r\n```ts\r\ndeclare interface SymbolConstructor {\r\n\t/**\r\n\t * Returns a new unique Symbol value.\r\n\t * @param description Description of the new symbol value.\r\n\t */\r\n\t(description?: string | number): new symbol;\r\n\r\n\t/**\r\n\t * Returns a Symbol object from the global symbol registry matching the given key if found.\r\n\t * Otherwise, returns a new symbol with this key.\r\n\t * @param key key to search for.\r\n\t */\r\n\tfor\u003cT extends string>(key: T): global symbol T;\r\n\t// or, until GH-35909 is implemented:\r\n\tfor(key: string): new symbol;\r\n}\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\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. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n## See also\r\n\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/36468>\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/35909> (`global symbol \"\u003cname>\"` proposal)\r\n- \u003chttps://github.com/microsoft/TypeScript/pull/24738>\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/24506>\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/40106>\r\n- \u003chttps://github.com/microsoft/TypeScript/pull/42543>\r\n- \u003chttps://github.com/microsoft/TypeScript/issues/53282>","author":{"url":"https://github.com/ExE-Boss","@type":"Person","name":"ExE-Boss"},"datePublished":"2020-03-19T00:26:46Z","url":"https://github.com/microsoft/TypeScript/issues/37469"}
| 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:630cf786-94cc-4858-e437-a26b6cda96d1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B326:99B56:236C63:3200DB:6B0468F5 |
| html-safe-nonce | bd7df6c7eabe457e3762fd63b4ef74947f0a1826e63551b2d3997ad77d28d4cb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzI2Ojk5QjU2OjIzNkM2MzozMjAwREI6NkIwNDY4RjUiLCJ2aXNpdG9yX2lkIjoiNTM2MTg2MzU0MDkyNjA4MTI2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fbc2bad204f30e099817cd071adc358f922fa93a23400613754a0a04247ded28 |
| hovercard-subject-tag | issue:584082162 |
| 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/37469/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2073c1ea2291355d0550a9f838f5c47b015df96314a5fdd4418954850ab891bd/microsoft/TypeScript/issues/37469 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2073c1ea2291355d0550a9f838f5c47b015df96314a5fdd4418954850ab891bd/microsoft/TypeScript/issues/37469 |
| og:image:alt | Search Terms unique symbol new unique symbol new symbol Suggestion I request that unique symbol be allowed as the return type of a function declaration. Alternatively, it might be better to use new... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ExE-Boss |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| 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