Title: Indexed symbol types · Issue #60944 · microsoft/TypeScript · GitHub
Open Graph Title: Indexed symbol types · Issue #60944 · microsoft/TypeScript
X Title: Indexed symbol types · Issue #60944 · microsoft/TypeScript
Description: 🔍 Search Terms "non-unique symbol types", "symbol type with key", "indexed symbol types" ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn't change the runtime behavior of existin...
Open Graph Description: 🔍 Search Terms "non-unique symbol types", "symbol type with key", "indexed symbol types" ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn'...
X Description: 🔍 Search Terms "non-unique symbol types", "symbol type with key", "indexed symbol types" ✅ Viability Checklist This wouldn't be a breaking change in existing TypeS...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/60944
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Indexed symbol types","articleBody":"### 🔍 Search Terms\n\n\"non-unique symbol types\", \"symbol type with key\", \"indexed symbol types\"\n\n\n\n### ✅ Viability Checklist\n\n- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\n- [x] This wouldn't change the runtime behavior of existing JavaScript code\n- [x] This could be implemented without emitting different JS based on the types of the expressions\n- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\n- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types\n- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals\n\n### ⭐ Suggestion\n\nTypeScript should be able to express symbol types indexed with their key, reflecting the behavior of JavaScript's `Symbol.for(\"some key\")`, by a new syntax like `symbol\u003c\"some key\">`.\n\nThis feature won't break existing code if it doesn't come with a change to the types of `Symbol.for`, `Symbol.keyFor`, and `Symbol.prototype.description`, but I'd rather like to see it happen, possibly behind a new tsconfig option like `\"indexedSymbolTypeInference\": true`.\n\n### 📃 Motivating Example\n\n```typescript\nconst symbolForSomeKeyDefinedInVersionA = Symbol.for(\"some key\")\nconst symbolForSomeKeyDefinedInVersionB = Symbol.for(\"some key\")\nconst shouldBeAssignable: {\n\t[symbolForSomeKeyDefinedInVersionA]: undefined\n} = {\n\t// Statically fails here for now.\n\t[symbolForSomeKeyDefinedInVersionB]: undefined,\n}\n```\n\n### 💻 Use Cases\n\n#### 1. What do you want to use this for?\n\nMaking multiple versions of the same library compatible.\n\nSometimes a library generates objects with a private property at a unique symbol key and use it as some kind of marker to statically or dynamically determine if an object is really generated or already processed with the library, while allowing users to define arbitrary properties on it as much as possible.\n\nBut what if a user has to end up depending on multiple versions of the library somehow? To address this, the library should accept objects from other versions of the same library, so the library might want to start using non-unique symbols for the purpose. This does work at runtime but not at compile time due to the absence of indexed symbol types.\n\nUsing a string key instead of a non-unique symbol key invades the string key space of such an object at runtime, and could conflict with an index signature at compile time.\n\n#### 2. What shortcomings exist with current approaches?\n\nThere's no current approaches for this.\n\n#### 3. What workarounds are you using in the meantime?\n\nNone.","author":{"url":"https://github.com/yuhr","@type":"Person","name":"yuhr"},"datePublished":"2025-01-09T19:12:05Z","url":"https://github.com/microsoft/TypeScript/issues/60944"}
| 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:adbbdcbd-86ea-79dc-3efa-96c3b6f89ca3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E700:99B56:4B9861:6AD915:6B0472B5 |
| html-safe-nonce | aed83ef909ee07f91d555c2f3a22ce97c42b07177facb50dd7473ee2d11c12ba |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzAwOjk5QjU2OjRCOTg2MTo2QUQ5MTU6NkIwNDcyQjUiLCJ2aXNpdG9yX2lkIjoiNDYzNDE2OTk0MjA4OTE2NzU0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c54edd35536b40a48adc7b68bd3495f02cb8a77de2e8d9256581dcf1a31f3d20 |
| hovercard-subject-tag | issue:2778578846 |
| 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/60944/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b27b82b7465b318fc438d5a18a1d375b5476dbe8ecaf19968b2aec134befce50/microsoft/TypeScript/issues/60944 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b27b82b7465b318fc438d5a18a1d375b5476dbe8ecaf19968b2aec134befce50/microsoft/TypeScript/issues/60944 |
| og:image:alt | 🔍 Search Terms "non-unique symbol types", "symbol type with key", "indexed symbol types" ✅ Viability Checklist This wouldn't be a breaking change in existing TypeScript/JavaScript code This wouldn'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yuhr |
| 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