Title: Object values are not assignable when wrapped in a Partial · Issue #26266 · microsoft/TypeScript · GitHub
Open Graph Title: Object values are not assignable when wrapped in a Partial · Issue #26266 · microsoft/TypeScript
X Title: Object values are not assignable when wrapped in a Partial · Issue #26266 · microsoft/TypeScript
Description: TypeScript Version: Version 3.1.0-dev.20180807 Search Terms: keyof mapped partial Code Compiled with --strictNullChecks: interface Value Open Graph Description: TypeScript Version: Version 3.1.0-dev.20180807 Search Terms: keyof mapped partial Code Compiled with --strictNullChecks: interface Value X Description: TypeScript Version: Version 3.1.0-dev.20180807 Search Terms: keyof mapped partial Code Compiled with --strictNullChecks: interface Value<T> { value: T; } interface Builder<T> { buildVal...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26266
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Object values are not assignable when wrapped in a Partial","articleBody":"**TypeScript Version:** Version 3.1.0-dev.20180807\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** keyof mapped partial\r\n\r\n**Code**\r\n\r\nCompiled with `--strictNullChecks`:\r\n\r\n```ts\r\ninterface Value\u003cT> {\r\n value: T;\r\n}\r\n\r\ninterface Builder\u003cT> {\r\n buildValue(): Value\u003cT>;\r\n}\r\n\r\ntype BuilderMap\u003cKeys extends PropertyKey> = {\r\n [K in Keys]: Builder\u003cany>;\r\n}\r\n\r\ntype ValueMap\u003cKeys extends PropertyKey> = {\r\n [K in Keys]: Value\u003cany>;\r\n};\r\n\r\nfunction makeFooMap\u003cMap extends BuilderMap\u003c\"foo\">>(builderMap: Map) {\r\n const valueMap: Partial\u003cValueMap\u003ckeyof Map>> = {};\r\n valueMap[\"foo\"] = builderMap[\"foo\"].buildValue();\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThe code compiles without errors.\r\n\r\n**Actual behavior:**\r\n\r\nThe compiler dislikes the `valueMap[\"foo\"]` assignment:\r\n\r\n```\r\nbug.ts:19:5 - error TS2322: Type 'Value\u003cany>' is not assignable to type 'ValueMap\u003ckeyof Map>[\"foo\"]'.\r\n\r\n19 valueMap[\"foo\"] = builderMap[\"foo\"].buildValue();\r\n ~~~~~~~~~~~~~~~\r\n```\r\n\r\nTested versions:\r\n\r\n- 2.9.2: no error\r\n- 3.0.1: reports error\r\n- 3.1.0-dev.20180807: reports error\r\n\r\nChanging the code to remove the `Partial` and using a type assertion seems to work:\r\n\r\n```ts\r\nfunction makeFooMap\u003cMap extends BuilderMap\u003c\"foo\">>(builderMap: Map) {\r\n const valueMap: ValueMap\u003ckeyof Map> = {} as ValueMap\u003ckeyof Map>;\r\n valueMap[\"foo\"] = builderMap[\"foo\"].buildValue(); // no error anymore\r\n}\r\n```\r\n\r\nGetting rid of the `keyof` and explicitly providing a list of keys also works:\r\n\r\n```ts\r\nfunction makeFooMap\u003cMap extends BuilderMap\u003c\"foo\">>(builderMap: Map) {\r\n const valueMap: Partial\u003cValueMap\u003c\"foo\">> = {};\r\n valueMap[\"foo\"] = builderMap[\"foo\"].buildValue(); // no error anymore\r\n}\r\n```\r\n\r\n**Playground Link:** [Playground Link](https://www.typescriptlang.org/play/#src=interface%20Value%3CT%3E%20%7B%0A%20%20%20%20value%3A%20T%3B%0A%7D%0A%0Ainterface%20Builder%3CT%3E%20%7B%0A%20%20%20%20buildValue()%3A%20Value%3CT%3E%3B%0A%7D%0A%0Atype%20BuilderMap%3CKeys%20extends%20PropertyKey%3E%20%3D%20%7B%0A%20%20%20%20%5BK%20in%20Keys%5D%3A%20Builder%3Cany%3E%3B%0A%7D%0A%0Atype%20ValueMap%3CKeys%20extends%20PropertyKey%3E%20%3D%20%7B%0A%20%20%20%20%5BK%20in%20Keys%5D%3A%20Value%3Cany%3E%3B%0A%7D%3B%0A%0Afunction%20makeFooMap%3CMap%20extends%20BuilderMap%3C%22foo%22%3E%3E(builderMap%3A%20Map)%20%7B%0A%20%20%20%20const%20valueMap%3A%20Partial%3CValueMap%3Ckeyof%20Map%3E%3E%20%3D%20%7B%7D%3B%0A%20%20%20%20valueMap%5B%22foo%22%5D%20%3D%20builderMap%5B%22foo%22%5D.buildValue()%3B%0A%7D)\r\n\r\n**Related Issues:** #25010 maybe?\r\n","author":{"url":"https://github.com/rraval","@type":"Person","name":"rraval"},"datePublished":"2018-08-07T17:25:44Z","url":"https://github.com/microsoft/TypeScript/issues/26266"}
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:57424f4f-5457-52b3-a639-20ca141e1c53 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id 830E:158DF1:B1132B:EA1A07:6B01BE79 html-safe-nonce c6f91afd8ee13d7da0f8439d2d6f9715b4d378a3055da45a9eccf9cbb1e48cce visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzBFOjE1OERGMTpCMTEzMkI6RUExQTA3OjZCMDFCRTc5IiwidmlzaXRvcl9pZCI6IjUyMjgwOTk0OTQ2MTYzNTAzMjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac 8e4bb66c62a4b7168a515d06f509f20e2d7e2d08125cd0ec9820fd88d447916f hovercard-subject-tag issue:348415608 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/26266/issue_layout twitter:image https://opengraph.githubassets.com/791501e06d05914111867ba0b5bae0b423b2adc3b4003d31d321cd87d68db7b1/microsoft/TypeScript/issues/26266 twitter:card summary_large_image og:image https://opengraph.githubassets.com/791501e06d05914111867ba0b5bae0b423b2adc3b4003d31d321cd87d68db7b1/microsoft/TypeScript/issues/26266 og:image:alt TypeScript Version: Version 3.1.0-dev.20180807 Search Terms: keyof mapped partial Code Compiled with --strictNullChecks: interface Value og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username rraval 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
URLs of crawlers that visited me.