Title: Cannot assign property to same type with generic key · Issue #32693 · microsoft/TypeScript · GitHub
Open Graph Title: Cannot assign property to same type with generic key · Issue #32693 · microsoft/TypeScript
X Title: Cannot assign property to same type with generic key · Issue #32693 · microsoft/TypeScript
Description: TypeScript Version: 3.6.0-dev.20190803 Search Terms: assigning keyof generic key Code type A = { a: number } type B = { b: number } interface Foo { a: A b: B } declare let target: Foo declare let source: Foo declare let key: keyof Foo ta...
Open Graph Description: TypeScript Version: 3.6.0-dev.20190803 Search Terms: assigning keyof generic key Code type A = { a: number } type B = { b: number } interface Foo { a: A b: B } declare let target: Foo declare let s...
X Description: TypeScript Version: 3.6.0-dev.20190803 Search Terms: assigning keyof generic key Code type A = { a: number } type B = { b: number } interface Foo { a: A b: B } declare let target: Foo declare let s...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32693
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot assign property to same type with generic key","articleBody":"**TypeScript Version:** 3.6.0-dev.20190803\r\n\r\n**Search Terms:** assigning keyof generic key\r\n\r\n**Code**\r\n\r\n```ts\r\ntype A = { a: number }\r\ntype B = { b: number }\r\n\r\ninterface Foo {\r\n a: A\r\n b: B\r\n}\r\n\r\ndeclare let target: Foo\r\ndeclare let source: Foo\r\ndeclare let key: keyof Foo\r\n\r\ntarget[key] = source[key]\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nI expect it to allow the assignment. Since `typeof target` and `typeof source` are the same, I expect `typeof target[key]` to always be the same as `typeof source[key]`.\r\n\r\n**Actual behavior:**\r\n\r\n> error TS2322: Type 'A | B' is not assignable to type 'A & B'.\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/#code/C4TwDgpgBAglC8UDeUCGAuKA7ArgWwCMIAnKAXwChRIoAhBZKAzXQk8iigSy2BIDNUAY2gAxAPbjkFKLLSYYMuczoVKFACYQhAG1TFoOiMCjB9Ac2OYJ4zdr0GoRkwGdxOYiOuS7u-YeMoAGsIEEwQkHF+KBtOM2JLYABtCIBdBjcPERTQ1IogA\r\n\r\n**Related Issues:** #31665 (but it was closed and the comments seem to indicate that this should work 🤔) ping @RyanCavanaugh ","author":{"url":"https://github.com/LinusU","@type":"Person","name":"LinusU"},"datePublished":"2019-08-03T12:10:18Z","url":"https://github.com/microsoft/TypeScript/issues/32693"}
| 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:4c4902dd-5eec-1a5a-8915-4a64fe0ebdc9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD18:3C21B:A35BFE:D47EEF:6B00E3FE |
| html-safe-nonce | 74316e7b76f08869285fa3a2e53872620b7090fbc5eb24756f81f2f62b2c8a5a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDE4OjNDMjFCOkEzNUJGRTpENDdFRUY6NkIwMEUzRkUiLCJ2aXNpdG9yX2lkIjoiMjE2NTA0ODMzOTQ1OTAwNzQ4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3fbe9737009752f326a202771bbb845af10386a36de7ed756e243b32bdb4f80c |
| hovercard-subject-tag | issue:476445779 |
| 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/32693/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad5b2c8ee21aab1202f9b4d0ee471aaa8253d29dc53a99844b94a4b739a699e4/microsoft/TypeScript/issues/32693 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad5b2c8ee21aab1202f9b4d0ee471aaa8253d29dc53a99844b94a4b739a699e4/microsoft/TypeScript/issues/32693 |
| og:image:alt | TypeScript Version: 3.6.0-dev.20190803 Search Terms: assigning keyof generic key Code type A = { a: number } type B = { b: number } interface Foo { a: A b: B } declare let target: Foo declare let s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LinusU |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width