Title: Symbol type is incorrectly generalized when used as a property value of an object literal · Issue #36876 · microsoft/TypeScript · GitHub
Open Graph Title: Symbol type is incorrectly generalized when used as a property value of an object literal · Issue #36876 · microsoft/TypeScript
X Title: Symbol type is incorrectly generalized when used as a property value of an object literal · Issue #36876 · microsoft/TypeScript
Description: TypeScript Version: 3.7.5 Search Terms: symbol infer type Expected behavior: Symbol const uniqueSymbol = Symbol() when used as property value in an object literal is inferred as unique type typeof uniqueSymbol. Actual behavior: Symbol co...
Open Graph Description: TypeScript Version: 3.7.5 Search Terms: symbol infer type Expected behavior: Symbol const uniqueSymbol = Symbol() when used as property value in an object literal is inferred as unique type typeof ...
X Description: TypeScript Version: 3.7.5 Search Terms: symbol infer type Expected behavior: Symbol const uniqueSymbol = Symbol() when used as property value in an object literal is inferred as unique type typeof ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36876
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Symbol type is incorrectly generalized when used as a property value of an object literal","articleBody":"**TypeScript Version:** 3.7.5\r\n\r\n**Search Terms:** symbol infer type\r\n\r\n**Expected behavior:**\r\n\r\nSymbol `const uniqueSymbol = Symbol()` when used as property value in an object literal is inferred as unique type `typeof uniqueSymbol`.\r\n\r\n**Actual behavior:**\r\n\r\nSymbol `const uniqueSymbol = Symbol()` when used as property value in an object literal is inferred as general type `symbol`.\r\n\r\n**Related Issues:**\r\n\r\n**Code**\r\n```ts\r\nconst uniqueSymbol = Symbol()\r\n\r\n// Example of incorrect inference (unique symbol is generalized to type `symbol`)\r\n\r\nconst foo = {\r\n prop: uniqueSymbol,\r\n}\r\n\r\ntype Foo = typeof foo // { prop: symbol }\r\n\r\n// Workarounds for incorrect behavior\r\n\r\nconst bar = {\r\n prop: uniqueSymbol as typeof uniqueSymbol,\r\n}\r\n\r\ntype Bar = typeof bar // { prop: typeof uniqueSymbol }\r\n\r\nconst genericFactory = \u003cT>(value: T) => ({ prop: value })\r\n\r\nconst baz = genericFactory(uniqueSymbol)\r\n\r\ntype Baz = typeof baz // { prop: typeof uniqueSymbol }\r\n\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n```ts\r\n\"use strict\";\r\nconst uniqueSymbol = Symbol();\r\n// Example of incorrect inference (unique symbol is generalized to type `symbol`)\r\nconst foo = {\r\n prop: uniqueSymbol,\r\n};\r\n// Workarounds for incorrect behavior\r\nconst bar = {\r\n prop: uniqueSymbol,\r\n};\r\nconst genericFactory = (value) => ({ prop: value });\r\nconst baz = genericFactory(uniqueSymbol);\r\n\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": false,\r\n \"alwaysStrict\": true,\r\n \"allowUnreachableCode\": false,\r\n \"allowUnusedLabels\": false,\r\n \"downlevelIteration\": false,\r\n \"noEmitHelpers\": false,\r\n \"noLib\": false,\r\n \"noStrictGenericChecks\": false,\r\n \"noUnusedLocals\": false,\r\n \"noUnusedParameters\": false,\r\n \"esModuleInterop\": true,\r\n \"preserveConstEnums\": false,\r\n \"removeComments\": false,\r\n \"skipLibCheck\": false,\r\n \"checkJs\": false,\r\n \"allowJs\": false,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": false,\r\n \"emitDecoratorMetadata\": false,\r\n \"target\": \"ES2017\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=24&pc=1#code/MYewdgzgLgBArmAlgRzgUwMoE8C2AjEAGxgF4Zt8iAKASgCg6B6RmAUQA8BDHAB0LRggAZjERhQAJwlpgsMULTTxAqghToYEXAWKIIMAOZowizoUQAvNABMYUEHaw8BAAy2VCL+nVCRYQkAcyAG86GBgeCRAeAC54JFRMbSIAGjoAXwYoJwEAMUDSR2dhGACHGGYYYIio2M1k4kymFgB1EAkAa04ohGt9AIlRcXbpWRg8NAALTgA3RHaGX2hx7sLQ8MjouLVEih0YTn1s4pEd9D3UjKycmAAhVbJjtBK8VcrqzbqnkrOkjxgmktYEYTBJEMBcpxZO0sIUADwAFQAfFQZmZ0HEETRSEiYFQPrU4mjCBp0t4gSsLIUQYpwZDoRIsKoEucGt4nndOFTHjkXlyKiwCVsis9Tiy-vtMkA)\r\n ","author":{"url":"https://github.com/pmeller","@type":"Person","name":"pmeller"},"datePublished":"2020-02-19T18:41:38Z","url":"https://github.com/microsoft/TypeScript/issues/36876"}
| 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:5877a63a-b8b8-e738-6102-7c175e4e4c7b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E02A:D7239:9BA1D1:DA5C3C:6B048A58 |
| html-safe-nonce | 9f4b9f8bcf7db5b022b247df0acd1ea349771dea5585c3df71a9afcdaaa0d5cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDJBOkQ3MjM5OjlCQTFEMTpEQTVDM0M6NkIwNDhBNTgiLCJ2aXNpdG9yX2lkIjoiODU0MzQzMDg1MjU3Nzg4ODg1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1d133f3d883206f4dd210469103bc746d8658351b29522002eaff27b9fe2f70e |
| hovercard-subject-tag | issue:567764018 |
| 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/36876/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e77d597c9852cca8887060885167c08e101da14d961d98e436fa99d8ab5ad48d/microsoft/TypeScript/issues/36876 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e77d597c9852cca8887060885167c08e101da14d961d98e436fa99d8ab5ad48d/microsoft/TypeScript/issues/36876 |
| og:image:alt | TypeScript Version: 3.7.5 Search Terms: symbol infer type Expected behavior: Symbol const uniqueSymbol = Symbol() when used as property value in an object literal is inferred as unique type typeof ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pmeller |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d5c152376e38b7d2e37f3d5179be29a73bee93b85110da28a4eebe1159cdc70 |
| 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 | f5017e8ff4ea25a8011fcf0f2a0e430c60dc86c8 |
| 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