Title: Removing optional modifier in homomorphic mapped types does not work in generic contexts since 5.5.x · Issue #59902 · microsoft/TypeScript · GitHub
Open Graph Title: Removing optional modifier in homomorphic mapped types does not work in generic contexts since 5.5.x · Issue #59902 · microsoft/TypeScript
X Title: Removing optional modifier in homomorphic mapped types does not work in generic contexts since 5.5.x · Issue #59902 · microsoft/TypeScript
Description: 🔎 Search Terms optional modifier, required fields, generic, NonNullable, strictNullChecks, homomorphic mapped types 🕗 Version & Regression Information This changed between versions 5.4.5 and 5.5.2 This changed in commit or PR e418f8d (as...
Open Graph Description: 🔎 Search Terms optional modifier, required fields, generic, NonNullable, strictNullChecks, homomorphic mapped types 🕗 Version & Regression Information This changed between versions 5.4.5 and 5.5.2 ...
X Description: 🔎 Search Terms optional modifier, required fields, generic, NonNullable, strictNullChecks, homomorphic mapped types 🕗 Version & Regression Information This changed between versions 5.4.5 and 5....
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59902
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Removing optional modifier in homomorphic mapped types does not work in generic contexts since 5.5.x","articleBody":"### 🔎 Search Terms\r\n\r\noptional modifier, required fields, generic, NonNullable, strictNullChecks, homomorphic mapped types\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 5.4.5 and 5.5.2\r\n- This changed in commit or PR e418f8d12c5f1b6c10fc3127764f34dad44d4586 (as reported by `every-ts`)\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play/?ts=5.5.4#code/MYewdgzgLgBApgDwIYFsAOAbOMC8MA8AKvAlHGACYQzQBOAlmAOYB8AFAJQBcMSYAnrhYwA3gCgYMAPRSYAJTiYkwRkxgB3elAAWvATTRwVAM3rAaAVwBGAWij9DMEMZgADOqtcwUSANZxqHWx7Q2pQWlojWCQmJEYAOglpWRDsYjwPZgBuMSTUmABlEBQ4AHk0KHpwJAxcURgAbX9BRhhCAF0Afh4ARhgAXxzJPIdsAEEMDAUARwt6SIo6kUbmmFbm50LisoqqsBr2m26YPsHcyXyZuYWANRqLALqJqbhZ+bgKJrh+Teer94o7RySRkMAAwsUlIxqK0AKzxAAs8QQABoYFYLLBTGBsHD4vCEElQJBYAgeP9bvdHngLJQ4NiPucYJEoBZaGAYAgcoMgA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nconst example = \u003cT extends string>(): any => {\r\n // Replacing with any specific sub-type of `string` makes the types correct again.\r\n // type T = string;\r\n\r\n type SomeOptional = { [key in T]?: 1 };\r\n \r\n type AllRequired = { [key in keyof SomeOptional]-?: 1 };\r\n\r\n type RequiredValues = AllRequired[keyof AllRequired];\r\n\r\n // Complains in 5.4.x, but fine in 5.5.x\r\n const x: RequiredValues = undefined\r\n\r\n return x;\r\n};\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nUsing `-?` leaves the fields marked as optional, and taking the values of the resulting type gives a union with `undefined`.\r\n\r\n### 🙂 Expected behavior\r\n\r\nUsing `-?` makes all fields required, and taking the values of the resulting type gives a union of field types.\r\n\r\n### Additional information about the issue\r\n\r\nRequires a `--strictNullChecks` flag.\r\n\r\nReplacing `keyof SomeOptional` with `NonNullable\u003ckeyof SomeOptional>` or `keyof SomeOptional as keyof SomeOptional` fixes the issue. It looks like this problem is limited to homomorphic mapped types.\r\n\r\nUsing `Required\u003c{ [P in keyof SomeOptional]: 1; }>` in place of `{ [key in keyof SomeOptional]-?: 1 }` results in the same behaviour.","author":{"url":"https://github.com/Fullfungo","@type":"Person","name":"Fullfungo"},"datePublished":"2024-09-09T11:52:07Z","url":"https://github.com/microsoft/TypeScript/issues/59902"}
| 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:9894ca74-474b-f80a-f200-528686d221f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD9E:AC748:962D10:C15360:6B0510A8 |
| html-safe-nonce | fb32244a29e3910fbbd18ce5f7ca385cbd5804693ecb73d67134379044596b6b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDlFOkFDNzQ4Ojk2MkQxMDpDMTUzNjA6NkIwNTEwQTgiLCJ2aXNpdG9yX2lkIjoiODIyNzE0MjM4NzA4OTM0NjcyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f0022cb7574df8698e48c69060121d25fd0b51fb079b2811162e3ae51aea4580 |
| hovercard-subject-tag | issue:2513747262 |
| 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/59902/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a35b274d1134d2b0be4e534949d51798ccc93062bface321e35451af99b1fdc/microsoft/TypeScript/issues/59902 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a35b274d1134d2b0be4e534949d51798ccc93062bface321e35451af99b1fdc/microsoft/TypeScript/issues/59902 |
| og:image:alt | 🔎 Search Terms optional modifier, required fields, generic, NonNullable, strictNullChecks, homomorphic mapped types 🕗 Version & Regression Information This changed between versions 5.4.5 and 5.5.2 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fullfungo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| 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