Title: TS Symbol typing clashes with standard, idiomatic JS · Issue #64585 · microsoft/TypeScript · GitHub
Open Graph Title: TS Symbol typing clashes with standard, idiomatic JS · Issue #64585 · microsoft/TypeScript
X Title: TS Symbol typing clashes with standard, idiomatic JS · Issue #64585 · microsoft/TypeScript
Description: TS Symbol identity is ineffective TypeScript's typing of symbol identity clashes with actual JavaScript semantics, making standard, idiomatic use of JS symbols difficult or impossible. Search terms Symbol.for, global symbol registry, uni...
Open Graph Description: TS Symbol identity is ineffective TypeScript's typing of symbol identity clashes with actual JavaScript semantics, making standard, idiomatic use of JS symbols difficult or impossible. Search terms...
X Description: TS Symbol identity is ineffective TypeScript's typing of symbol identity clashes with actual JavaScript semantics, making standard, idiomatic use of JS symbols difficult or impossible. Search t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/64585
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TS Symbol typing clashes with standard, idiomatic JS","articleBody":"# TS Symbol identity is ineffective\n\nTypeScript's typing of symbol identity clashes with actual JavaScript semantics, making standard, idiomatic use of JS symbols difficult or impossible.\n\n## Search terms\n\n`Symbol.for`, global symbol registry, `unique symbol`, well-known symbol, computed symbol property, declaration emit\n\n## Version and reproduction\n\nThe supplied Playground link selects TypeScript 6.0.3. I have not tested it against newer TypeScript versions.\n\n[Playground reproduction (TypeScript 6.0.3)](https://www.typescriptlang.org/play/?target=99&jsx=0&ts=6.0.3#code/PTAEBUAsFNQYwPYBNYElQHcCGA7ALqHgqAK4DO0AXAFAijABUD1iOZBZAljgOYA2sALygAygE8AtgCMEfAHQAzBACcAFAHIuvAeoCUAbhYI2BPBm4BGUMPHTZilRrPc9h1u0LmcAJmujJMvJKaurOOK5GJqQ4nACOfraBGiQxsSTQEe4EGNB8fADSOAgYOAkB9hJYeHCQbsYeOXmFxT5ldvJEInjK3DzgWDyGdAzAtEy0YFCcZKDThDCgckhyeDOIKKA80DjQylXQSKAKyggSoFgyAG7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zrG8PdtBJGA+i1J4-WsaPT+gGUNAPHMJwvDiaIlRQAAUWw3EcCQICsFhjgET8zBODwSBzkwCsIRRSGa0CHKsDRGZ2D2XgbnEiuBFy-BZgkejObbgLICwGYnfUXAxC0uXWypLByFgYvnjILhTK7HfND+LThPCAg2wPw4FbAFtuBQbCzNgJWddVm8M9inOta+WNrrVc+tYqGwBE-ZWJtApx3Nl4BKSVKoAHZ1LVQAMwNSahDFoe1R7zWjsjFcOCwZnSzghEh4RroTn9kgdBfgFzXlRpubc2MPpLn6hqO88p2G-ziHeB8vDiEVlBjgcGIjIaAxfKvRu8NvxRzuug5h0BM6h0QjofOhcCYl0IqTKS8FthwFgF2cMPc+4xlkPAfeFAR4IhID0LKMxtSmSNOkMgtw6DgEtOoTy353KgAAD6gHciFQJwT4phPcpQ9yWkdJ6T4mQhQ5F26H0JvhA4H9zwhIQUlcSXjzI+MNlpOYCTV5cB4DgC4DEWwX2ydwGJyVVAWHQQANnUt7BkCjaFKKDoki6lMcaRxTn7Y6PS459MTk6Qwyc+CpzoenfhEyEJXVxhhbRRNdHl30RQHARiTI5lMb3Fo-dLHCQPrY+xnBHFfBcaCNxHjJjeN8bufxQS6k4FeeE1InyokSJaDEsW8TJZDRDskhYxciYZNqdE3JninlFNmBLAgZTOAVKqbAGpTyYWNOaW0hqlCumjOEU0SGqj+mUJxkAA)\n\n## JavaScript behavior\n\n`Symbol.for(\"twin\")` returns the same symbol whenever the registry key is `\"twin\"`; `Symbol(\"unique\")` creates a fresh symbol on each call. Well-known symbols such as `Symbol.match` are stable values. The types of references to these values should reflect those identities where the key or symbol is known.\n\n## Code\n\nThe code below is copied from the Playground link above.\n\n```ts\n// The code I want to use:\n// /**\nconst single = Symbol.for('single');\nconst twin1 = Symbol.for('twin');\nconst twin2 = Symbol.for('twin');\nconst uniq = Symbol('unique');\nconst wellKnown = Symbol.match;\nconst wellKnown2 = Symbol.toStringTag;\n// */\n/**\n// This is the .d.ts code generated from above (without the shim).\ndeclare const single: unique symbol; // invalid - needs type like RegisteredSymbol\u003c'single'>\ndeclare const twin1: unique symbol; // invalid - needs type like RegisteredSymbol\u003c'twin'>\ndeclare const twin2: unique symbol; // invalid - needs type like RegisteredSymbol\u003c'twin'>\ndeclare const uniq: unique symbol; // valid\ndeclare const wellKnown: symbol; // invalid - needs to be `typeof Symbol.match`\ndeclare const wellKnown2: symbol; // invalid - needs to be `typeof Symbol.toStringTag`\n*/\n\n\nconst record1 = {\n [single]: 'single',\n [twin2]: 'twin',\n [uniq]: 'uniq',\n} as const;\nlet singleVal: string = record1[single] satisfies 'single';\n// @ ts-expect-error why are multiple Symbol.for('twin') lookups not identical?\n// Property '__@twin1@10' does not exist on type \\\n// '{ readonly [single]: \"single\"; readonly [twin2]: \"twin\"; readonly [uniq]: \"uniq\"; }'. \\\n// Did you mean '__@twin2@11'? (2551)\nlet twin1Val: string = record1[twin1] satisfies 'twin';\nlet twin2Val: string = record1[twin2] satisfies 'twin';\nlet uniqVal: string = record1[uniq] satisfies 'uniq';\n\nconst record2 = {\n ...record1,\n [uniq]: 'uniqNew',\n [wellKnown]: 'wellKnown',\n} as const;\nsingleVal = record2[single] satisfies 'single';\n// @ ts-expect-error Symbol.for('twin') lookups still aren't identical.\n// Property '__@twin1@10' does not exist on type \\\n// '{ readonly [uniq]: \"uniqNew\"; readonly [single]: \"single\"; readonly [twin2]: \"twin\"; }' \\\n// Did you mean '__@twin2@11'? (2551)\ntwin1Val = record2[twin1] satisfies 'twin';\ntwin2Val = record2[twin2] satisfies 'twin';\nuniqVal = record2[uniq] satisfies 'uniqNew';\n// @ ts-expect-error Extending a const spread with a well-known symbol makes strange.\n// Element implicitly has an 'any' type because expression of type 'symbol' can't be used \\\n// to index type '{ readonly [uniq]: \"uniqNew\"; readonly [single]: \"single\"; \\\n// readonly [twin2]: \"twin\"; }'. (7053)\nlet wellKnownVal: string = record2[wellKnown] satisfies 'wellKnown';\n\nconst record3 = {\n [single]: 'single',\n [twin2]: 'twin',\n [uniq]: 'uniq',\n [wellKnown]: 'wellKnown',\n} as const;\nsingleVal = record3[single] satisfies 'single';\n// @ ts-expect-error Presence of well-known symbol causes spurious union values.\n// Type '\"single\" | \"twin\" | \"uniq\" | \"wellKnown\"' does not satisfy the expected type '\"twin\"'.\n// Type '\"single\"' is not assignable to type '\"twin\"'. (1360)\ntwin1Val = record3[twin1] satisfies 'twin';\ntwin2Val = record3[twin2] satisfies 'twin';\nuniqVal = record3[uniq] satisfies 'uniq';\n// @ ts-expect-error Presence of well-known symbol causes spurious union values.\n// Type '\"single\" | \"twin\" | \"uniq\" | \"wellKnown\"' does not satisfy the expected type '\"wellKnown\"'.\n// Type '\"single\"' is not assignable to type '\"wellKnown\"'. (1360)\nwellKnownVal = record3[wellKnown] satisfies 'wellKnown';\n```\n\n## Actual behavior\n\n- Separate `Symbol.for(\"twin\")` calls are treated as separate `unique symbol` identities, so a property written using one call's result cannot reliably be read using the other's, even though both values are the same at runtime.\n- A `const` alias of a well-known symbol can widen to `symbol`. This loses the exact computed property key through object literals and spreads, producing erroneous indexed-access errors or unions of unrelated property values.\n- Declaration output can describe registered symbols as unrelated `unique symbol` values and well-known symbol aliases as plain `symbol`, losing useful identity information for consumers.\n\n## Expected behavior\n\n- Equal literal registry keys identify the same registered symbol type; different keys remain distinct. Unknown or union keys must stay conservative rather than acquire one fabricated unique identity.\n- Const aliases of known symbols retain their identity, and symbol-keyed property access resolves to the corresponding property's value type, including after a spread.\n- Emitted declarations preserve the symbol identity that consumers need to use those keys.\n\n## Related work\n\n- [#35909 — Can't evaluate equality of symbols made by `Symbol.for`](https://github.com/microsoft/TypeScript/issues/35909) reports that TypeScript treats two calls with the same registry key as disjoint `unique symbol` types. The `twin1`/`twin2` property accesses above show another consequence of that mismatch with JavaScript identity.\n- [#27524 — Assign a known symbol to a constant should retain type information](https://github.com/microsoft/TypeScript/issues/27524) asks for a `const` alias of a known symbol to retain the original symbol type. Losing that identity affects the `wellKnown` computed property and its subsequent accesses in this repro.\n- [#55901 — `unique symbol` lost on assignment to `const` despite type assertion](https://github.com/microsoft/TypeScript/issues/55901) describes a related widening case: `const a = u as typeof u` is inferred as `symbol` rather than `typeof u`. It illustrates why explicit assertions should not discard a symbol's known identity.\n- [PR #64451 — ES-conformant symbol typing](https://github.com/microsoft/TypeScript/pull/64451) proposes `RegisteredSymbol\u003cKey>` as the type of the memoized `unique symbol` permanently associated with `Key` in the global symbol registry. It also preserves narrow symbol types in const-like declarations and updates symbol-keyed property handling; its tests cover this repro and ensure unresolved keys do not acquire a fabricated single identity.\n","author":{"url":"https://github.com/michaelfig","@type":"Person","name":"michaelfig"},"datePublished":"2026-10-02T04:41:11Z","url":"https://github.com/microsoft/TypeScript/issues/64585"}
| 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:107305bc-c1eb-2272-757f-6b3d262a6104 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C492:2D6F70:654874:8DE3B9:6B047817 |
| html-safe-nonce | e3900b8c72cfee482b87cf7c3389711338326bfdca31abaac91cdcaa90f6b6f1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDkyOjJENkY3MDo2NTQ4NzQ6OERFM0I5OjZCMDQ3ODE3IiwidmlzaXRvcl9pZCI6IjY3NjI4NzI0NDExMzMxMDMxMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 40cbef3234f07c922c4d4bb621dc630060f4fcb04b6e58ac49f48c97c2c513ca |
| hovercard-subject-tag | issue:5672963637 |
| 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/64585/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9dd0fee19f475c8f61c04372ff5a175262fc0d62566441ea214ce97a2425febb/microsoft/TypeScript/issues/64585 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9dd0fee19f475c8f61c04372ff5a175262fc0d62566441ea214ce97a2425febb/microsoft/TypeScript/issues/64585 |
| og:image:alt | TS Symbol identity is ineffective TypeScript's typing of symbol identity clashes with actual JavaScript semantics, making standard, idiomatic use of JS symbols difficult or impossible. Search terms... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaelfig |
| 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