Title: Object type not assignable to equivalent value of mapped type · Issue #25010 · microsoft/TypeScript · GitHub
Open Graph Title: Object type not assignable to equivalent value of mapped type · Issue #25010 · microsoft/TypeScript
X Title: Object type not assignable to equivalent value of mapped type · Issue #25010 · microsoft/TypeScript
Description: Code // Pack<{ a: number }> is { a: { value: number } } type Pack
Open Graph Description: Code // Pack<{ a: number }> is { a: { value: number } } type Pack
X Description: Code // Pack<{ a: number }> is { a: { value: number } } type Pack<T> = { [K in keyof T]: { value: T[K] } }; function patch<T, K extends keyof T>(obj: Partial<Pack<T>>,...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/25010
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Object type not assignable to equivalent value of mapped type","articleBody":"**Code**\r\n\r\n```ts\r\n// Pack\u003c{ a: number }> is { a: { value: number } }\r\ntype Pack\u003cT> = { [K in keyof T]: { value: T[K] } };\r\n\r\nfunction patch\u003cT, K extends keyof T>(obj: Partial\u003cPack\u003cT>>, key: K, value: T[K]) {\r\n obj[key] = { value }; // error: Type '{ value: T[K]; }' is not assignable to type 'Pack\u003cT>[K]'.\r\n}\r\n```\r\n\r\nExample usage of `patch()`:\r\n```ts\r\ntype SomeType = {\r\n a: number, b: string\r\n};\r\n\r\nconst obj: Partial\u003cPack\u003cSomeType>> = {\r\n a: { value: 1 }\r\n}\r\n\r\npatch(obj, 'b', 'foo'); // desired outcome is for obj.b to equal 'foo'\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nDefinition of `patch()` function should be fine, and calling should produce the desired outcome.\r\n\r\n**Actual behavior:**\r\n\r\n`patch()` function fails to compile with error `Type '{ value: T[K]; }' is not assignable to type 'Pack\u003cT>[K]'` even though `{ value: T[K] }` does appear to be assignable to `Pack\u003cT>[K]`:\r\n\r\n```ts\r\nfunction getPack\u003cT, K extends keyof T>(obj: T, key: K): Pack\u003cT>[K] {\r\n const value = obj[key]; // T[K]\r\n return { value }; // { value: T[K]; }\r\n}\r\n```\r\n\r\n**Playground Link:** \r\nAdditional examples here: https://bit.ly/2le5qZq","author":{"url":"https://github.com/ethanroday","@type":"Person","name":"ethanroday"},"datePublished":"2018-06-15T22:54:58Z","url":"https://github.com/microsoft/TypeScript/issues/25010"}
| 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:48dd36aa-10ac-db66-b14b-aaefed9f8e3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88A0:157C65:2AB9272:38FC014:6B01C6A7 |
| html-safe-nonce | 328e6733986ec615191058b55e04b0690334f4e4c2d83191295c5394afec00d7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEEwOjE1N0M2NToyQUI5MjcyOjM4RkMwMTQ6NkIwMUM2QTciLCJ2aXNpdG9yX2lkIjoiMzM2MjIxNTgyMzAzMjgyODU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7af62b801b206ee63aa5e11de912db93e3f135aafbc9e0b31944cc0a4bed6cf2 |
| hovercard-subject-tag | issue:332935083 |
| 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/25010/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e6e2388f38cb9cb049d2b204bdd6b3c3635898678e8e45abd28ae42a67697bfe/microsoft/TypeScript/issues/25010 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e6e2388f38cb9cb049d2b204bdd6b3c3635898678e8e45abd28ae42a67697bfe/microsoft/TypeScript/issues/25010 |
| og:image:alt | Code // Pack<{ a: number }> is { a: { value: number } } type Pack |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ethanroday |
| 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