Title: Computed properties do not type check when they could · Issue #18596 · microsoft/TypeScript · GitHub
Open Graph Title: Computed properties do not type check when they could · Issue #18596 · microsoft/TypeScript
X Title: Computed properties do not type check when they could · Issue #18596 · microsoft/TypeScript
Description: TypeScript Version: 2.4.2 Code type A = { a: number, b: string }; const a: A = { a: 1, b: 'foo' }; const b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct) const propB: 'b' = 'b'; const c: A = { ...a, [propB]: 1...
Open Graph Description: TypeScript Version: 2.4.2 Code type A = { a: number, b: string }; const a: A = { a: 1, b: 'foo' }; const b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct) const propB: 'b...
X Description: TypeScript Version: 2.4.2 Code type A = { a: number, b: string }; const a: A = { a: 1, b: 'foo' }; const b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct) con...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/18596
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Computed properties do not type check when they could","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:** 2.4.2\r\n\r\n**Code**\r\n\r\n```ts\r\ntype A = { a: number, b: string };\r\n\r\nconst a: A = { a: 1, b: 'foo' };\r\n\r\nconst b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct)\r\n\r\nconst propB: 'b' = 'b';\r\nconst c: A = { ...a, [propB]: 123 }; // type checks even though i'm setting b to a number (incorrect)\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nLast statement should be invalid, since `propB` is of type `'b'`, which should be enough information for TS to know that i'm setting the `b` property.\r\n\r\n**Actual behavior:**\r\n\r\nLast statement is valid for TS. This also happens for union types of string or number literals. When the types for the values in those keys are the same, and attempting to set a value using a computed property, TS allows invalid values.","author":{"url":"https://github.com/leoasis","@type":"Person","name":"leoasis"},"datePublished":"2017-09-20T13:52:54Z","url":"https://github.com/microsoft/TypeScript/issues/18596"}
| 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:f12b2617-748a-200d-1288-e34f5fc96f7b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C534:157C65:13646A0:19E364A:6B012A25 |
| html-safe-nonce | 05fd6c2743666746d28436b381d8749ca92f47d0a0b311fea871fe16be6db3ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTM0OjE1N0M2NToxMzY0NkEwOjE5RTM2NEE6NkIwMTJBMjUiLCJ2aXNpdG9yX2lkIjoiODUxODY1ODI2NzE5MzM1NDc5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9414d93425dfe1c5096aefb4e44e75aa473775f0243105ce1aae742f98d7f250 |
| hovercard-subject-tag | issue:259171627 |
| 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/18596/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ef53769aa7d41d9e72a1c5bb36965bbe31938b6e88f466637ac93ff61009509a/microsoft/TypeScript/issues/18596 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ef53769aa7d41d9e72a1c5bb36965bbe31938b6e88f466637ac93ff61009509a/microsoft/TypeScript/issues/18596 |
| og:image:alt | TypeScript Version: 2.4.2 Code type A = { a: number, b: string }; const a: A = { a: 1, b: 'foo' }; const b: A = { ...a, b: 123 }; // doesn't type check, b should be string (correct) const propB: 'b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | leoasis |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width