Title: Regression 5.4: the new conditional type constraint is not working with a type parameter representing union type · Issue #57864 · microsoft/TypeScript · GitHub
Open Graph Title: Regression 5.4: the new conditional type constraint is not working with a type parameter representing union type · Issue #57864 · microsoft/TypeScript
X Title: Regression 5.4: the new conditional type constraint is not working with a type parameter representing union type · Issue #57864 · microsoft/TypeScript
Description: 🔎 Search Terms regression, type parameter, 5.4 🕗 Version & Regression Information This is a crash This changed between versions 5.3.3 and 5.4.2 ⏯ Playground Link https://www.typescriptlang.org/play?ts=5.4.2#code/C4TwDgpgBAggznAlgcwHYCUJw...
Open Graph Description: 🔎 Search Terms regression, type parameter, 5.4 🕗 Version & Regression Information This is a crash This changed between versions 5.3.3 and 5.4.2 ⏯ Playground Link https://www.typescriptlang.org/play...
X Description: 🔎 Search Terms regression, type parameter, 5.4 🕗 Version & Regression Information This is a crash This changed between versions 5.3.3 and 5.4.2 ⏯ Playground Link https://www.typescriptlang.org/...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57864
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression 5.4: the new conditional type constraint is not working with a type parameter representing union type","articleBody":"### 🔎 Search Terms\n\nregression, type parameter, 5.4\n\n### 🕗 Version & Regression Information\n\n- This is a crash\r\n- This changed between versions 5.3.3 and 5.4.2\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play?ts=5.4.2#code/C4TwDgpgBAggznAlgcwHYCUJwK4BtgA8MATsVBAB7ASoAmcUA9gEYBWEAxsANoC6AfFAC8sUgCgxAeklRuqPLgA0UeQFtmEYsux0IAM0SoItZXGDFDyXsMFzs6zafOXeY0JCgAxRPk1FSygAqjADyqojAgiIkZJTUdAzchnqaUAASEACGJlAAdPnJqYGZPq5QUAD86Vm05FQ09FDBYRFi5eVV3r7EBMU+QaHhkW3tAFyyGdnK+bld1D19Sk2DEfxlUON8ANwS7tAA6ozEANZwAAoWRwCsACwEAMp18Y0s7FxQAD4qClGwCCgYLB4QhzPz3ZTyXC4fj8XbgA5HU7CP5INCYHD4AignqvTjAT7fKEQn78IA\n\n### 💻 Code\n\nThis is the simplified code\r\n```ts\r\ntype AssignResult\u003cArr extends object[]> = Arr\r\n\r\n// [null, number, undefined, string] => [number, string]\r\ntype Filter\u003cArr, ToOmit> = Arr extends [infer Head, ...infer Tail]\r\n ? Head extends ToOmit\r\n ? Filter\u003cTail, ToOmit>\r\n : [Head, ...Filter\u003cTail, ToOmit>]\r\n : [];\r\n\r\ntype WorksPrior54\u003cS extends object | null> = AssignResult\u003cFilter\u003cS, null>>\r\n\r\ntype Works = AssignResult\u003cFilter\u003cobject | null, null>>\r\n```\r\n\u003cdetails>\r\n \u003csummary>This is the full code (error message is slightly different, but probably they are the same):\u003c/summary>\r\n\r\n```typescript\r\ntype AssignResult\u003cArr extends object[]> = Arr extends [...infer Rest extends object[], infer Last]\r\n ? {\r\n [K in keyof Last | keyof AssignResult\u003cRest>]: K extends keyof Last\r\n ? Last[K]\r\n : K extends keyof AssignResult\u003cRest>\r\n ? AssignResult\u003cRest>[K]\r\n : never;\r\n }\r\n : object;\r\n\r\ntype Filter\u003cArr, ToOmit> = Arr extends [infer Head, ...infer Tail]\r\n ? Head extends ToOmit\r\n ? Filter\u003cTail, ToOmit>\r\n : [Head, ...Filter\u003cTail, ToOmit>]\r\n : [];\r\n\r\ndeclare function assignByDescriptors\u003c\r\n Target extends object,\r\n // replace the two lines below to make it work with the this line\r\n // Sources extends (object | null | undefined)[],\r\n Source extends object | null | undefined,\r\n Sources extends Source[],\r\n Result extends AssignResult\u003c[Target, ...Filter\u003cSources, null | undefined>]> = AssignResult\u003c[Target, ...Filter\u003cSources, null | undefined>]>\r\n>(target: Target, ...sources: Sources): Result\r\n```\r\n\r\n\u003c/details>\n\n### 🙁 Actual behavior\n\nI would expect to have no error for 5.4, the same as there was no error before it. Especially considering that there were not breaking changes in 5.4 announcement.\r\n\r\nAs for the simplified code, there should be no difference between how `WorksPrior54` and `Works`.\r\n\r\nAs for the full version of the code, there should be no difference if part of `Sources` type parameter is extracted into an intermediate `Source` type parameter, or not\n\n### 🙂 Expected behavior\n\nError (in the simplified version): \r\n```\r\nTS2344: Type Filter\u003cS, null> does not satisfy the constraint object[]\r\nType [] | [unknown] is not assignable to type object[]\r\nType [unknown] is not assignable to type object[]\r\n```\r\nError (in the full version):\r\n```\r\nTS2344: Type\r\n[Target, ...Filter\u003cSources, null | undefined>]\r\ndoes not satisfy the constraint object[]\r\nType\r\nTarget | Filter\u003cSources, null | undefined>[number]\r\nis not assignable to type object\r\nType Filter\u003cSources, null | undefined>[number] is not assignable to type object\r\nType\r\n(Source extends null | undefined ? [] : [Source])[number] | (Source extends null | undefined ? [] : [Source])[number]\r\nis not assignable to type object\r\nType\r\n(Source extends null | undefined ? [] : [Source])[number]\r\nis not assignable to type object\r\n```\n\n### Additional information about the issue\n\n_No response_","author":{"url":"https://github.com/Alexsey","@type":"Person","name":"Alexsey"},"datePublished":"2024-03-20T18:12:52Z","url":"https://github.com/microsoft/TypeScript/issues/57864"}
| 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:493b4a68-3c1a-248f-9923-bca674fddeba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A640:5028D:2703B0:32AFC9:6B04F0E5 |
| html-safe-nonce | f0d8de4dc56ce0204b3eae98abc4fae3d9613da4f791751ec832c2b44fde7fc4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjQwOjUwMjhEOjI3MDNCMDozMkFGQzk6NkIwNEYwRTUiLCJ2aXNpdG9yX2lkIjoiMzc3OTk0NDQ5Nzg4MzE4MTI4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 67663fcbda06c28553e1d7f3d55935b1771b02ce267fed4fc868478a1970689b |
| hovercard-subject-tag | issue:2198232634 |
| 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/57864/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5513c7e9d67e56d80e1c25fa6d44ecfe081276908cd75ef8151706411f5295dd/microsoft/TypeScript/issues/57864 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5513c7e9d67e56d80e1c25fa6d44ecfe081276908cd75ef8151706411f5295dd/microsoft/TypeScript/issues/57864 |
| og:image:alt | 🔎 Search Terms regression, type parameter, 5.4 🕗 Version & Regression Information This is a crash This changed between versions 5.3.3 and 5.4.2 ⏯ Playground Link https://www.typescriptlang.org/play... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Alexsey |
| hostname | github.com |
| expected-hostname | github.com |
| None | c0ff704de2671f716381d0ef36115cddb81606dd5397a5b003230bb8c02d623b |
| 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 | cbe60d43d23e17438879ed212ad20068394651c4 |
| 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