Title: Incorrect inference of mapped substitution type in conditional involving a union of arrays (regression) · Issue #56018 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect inference of mapped substitution type in conditional involving a union of arrays (regression) · Issue #56018 · microsoft/TypeScript
X Title: Incorrect inference of mapped substitution type in conditional involving a union of arrays (regression) · Issue #56018 · microsoft/TypeScript
Description: 🔎 Search Terms "inference", "conditional type", "substitution type", "mapped type", "type constraint", "array", "union type" 🕗 Version & Regression Information This changed between versions 5.0.4 and 5.1.6 ⏯ Playground Link https://www.t...
Open Graph Description: 🔎 Search Terms "inference", "conditional type", "substitution type", "mapped type", "type constraint", "array", "union type" 🕗 Version & Regression Information This changed between versions 5.0.4 a...
X Description: 🔎 Search Terms "inference", "conditional type", "substitution type", "mapped type", "type constraint", "array", "union type" 🕗 ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/56018
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect inference of mapped substitution type in conditional involving a union of arrays (regression)","articleBody":"### 🔎 Search Terms\n\n\"inference\", \"conditional type\", \"substitution type\", \"mapped type\", \"type constraint\", \"array\", \"union type\"\n\n### 🕗 Version & Regression Information\n\nThis changed between versions 5.0.4 and 5.1.6\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play?ts=5.1.6#code/C4TwDgpgBAShB2BDAthAJlAvFAThRaA9vADYhQAUA3lANoDWAXFAAo6GQ6gDSEIAuswDOwHAEt4AcygBfKAB8oAV3hoIAMwnoAlLX4AofaEhQAYoUIAeACpQIAD2AI0Q3PiKlyFNhwhcQvOSKKmqa8Dp6CrAIKOgAfFj6UMlQtg5Oqq5wSKgYAPxQAOIQwIFClnAAjkpieGg2cQnMVTV1DYbG0MWlfOUwdo7OWTG5Cdg0tNxQElD0fITqsIKz84swk-yyhgD028pCiJIQRuDQAIJYZhaWtADkiLd5-Am7dABEiG8GnVAAQpfmKy0GiIPLMW4AI1usmeUFetA+XyAA\n\n### 💻 Code\n\n```ts\r\ntype Renamed = readonly ({ [k: PropertyKey]: string } | undefined)[]\r\n\r\ntype Foo\u003cT extends readonly (PropertyKey | undefined)[] | Renamed> =\r\n T extends Renamed ? GetKeys\u003cRequired\u003cT>> : Required\u003cT>\r\n// ~~~~~~~~~~\r\n// Type 'Required\u003cT>' does not satisfy the constraint 'Renamed'\r\n\r\ntype GetKeys\u003cR extends Renamed> = { [K in keyof R]: keyof R[K] }\r\n\r\n// usage\r\ntype A = Foo\u003c['a'?]> // [\"a\"]\r\ntype B = Foo\u003c[{ a?: 'b' }]> // [\"a\"]\r\n```\r\n\n\n### 🙁 Actual behavior\n\nTS fails to see that `Required\u003cT extends Renamed>` extends `Renamed`.\r\n\n\n### 🙂 Expected behavior\n\nIt should compile.\n\n### Additional information about the issue\n\nSubstitute `readonly (PropertyKey | undefined)[]` with something that is not an array and the problem disappears. \r\n\r\nI get the same error when I do `GetKeys\u003cId\u003cT>>` with `type Id\u003cT> = { [K in keyof T]: T[K] }`.\r\n\r\n`Extract\u003cRequired\u003cT>, Required\u003cRenamed>>` silences the error, but `Extract\u003cRequired\u003cT>, Renamed>` does not.","author":{"url":"https://github.com/geoffreytools","@type":"Person","name":"geoffreytools"},"datePublished":"2023-10-07T12:34:38Z","url":"https://github.com/microsoft/TypeScript/issues/56018"}
| 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:4eaf2d0e-a28f-bb27-99ba-635967884681 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 90A4:19F84C:2BD4920:37B6F94:6B019BB2 |
| html-safe-nonce | 5823b0c4df816c5acad4c877d8b7a3f2e7918eafaed3c9e5209067a2f83eba05 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEE0OjE5Rjg0QzoyQkQ0OTIwOjM3QjZGOTQ6NkIwMTlCQjIiLCJ2aXNpdG9yX2lkIjoiNTIzNzI3NDc1NTk0MTM3NDg5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c32b02cb1451ffb0279aa06ac23122e5ba3d7e3aeadadbc74c30c59973454f27 |
| hovercard-subject-tag | issue:1931335407 |
| 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/56018/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be26dfc72e5a03e47576d08b7e9dc7f70d94617a4a91d6f369bcb4385c9c2bfe/microsoft/TypeScript/issues/56018 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be26dfc72e5a03e47576d08b7e9dc7f70d94617a4a91d6f369bcb4385c9c2bfe/microsoft/TypeScript/issues/56018 |
| og:image:alt | 🔎 Search Terms "inference", "conditional type", "substitution type", "mapped type", "type constraint", "array", "union type" 🕗 Version & Regression Information This changed between versions 5.0.4 a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | geoffreytools |
| 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