Title: "Expression produces a union type that is too complex to represent" when using interfaces with large number of params for filtering and narrowing down certain keys · Issue #57863 · microsoft/TypeScript · GitHub
Open Graph Title: "Expression produces a union type that is too complex to represent" when using interfaces with large number of params for filtering and narrowing down certain keys · Issue #57863 · microsoft/TypeScript
X Title: "Expression produces a union type that is too complex to represent" when using interfaces with large number of params for filtering and narrowing down certain keys · Issue #57863 · microsoft/TypeScript
Description: 🔎 Search Terms Expression produces a union type that is too complex to represent, 2590, ts2590 🕗 Version & Regression Information This behavior occurs in 5.4.2 and above. On 5.3.3 it works fine ⏯ Playground Link https://www.typescriptlan...
Open Graph Description: 🔎 Search Terms Expression produces a union type that is too complex to represent, 2590, ts2590 🕗 Version & Regression Information This behavior occurs in 5.4.2 and above. On 5.3.3 it works fine ⏯ P...
X Description: 🔎 Search Terms Expression produces a union type that is too complex to represent, 2590, ts2590 🕗 Version & Regression Information This behavior occurs in 5.4.2 and above. On 5.3.3 it works fine...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57863
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Expression produces a union type that is too complex to represent\" when using interfaces with large number of params for filtering and narrowing down certain keys","articleBody":"### 🔎 Search Terms\n\nExpression produces a union type that is too complex to represent, 2590, ts2590\n\n### 🕗 Version & Regression Information\n\n- This behavior occurs in 5.4.2 and above. On 5.3.3 it works fine\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play?ts=5.4.2#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgVTABNNU4BvAKDhrgFdjTgB9BIgLjiToFsAjNAG5K1Wj2ABnCZgDmwAPydyccVNnBOEmFGQy4AX2G04wIglRFmq6XMUUTZi1ck2NcLTqR7DomtgAWmEhIwAA2zJBadsoBQSHhkTCa2roGRrSm5qbMscFhERBRSg5ZlrnxBVrJnt7pNNbqzFDAODAIEEjRKi6Nza3tSNWpPsYNck0t2G0dORB0KF1jLH1TA7PzSe4pXm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kImccAAAbzEQwdHEQuc67FVM0yEykANIk-W5NJcO1srvM9s48YzvDgAZDtosIAiA6u+7ACiIDYKEdCFwO1dzil4v4JztuFyHphUT7XAuUIj3PfzYChD5mBJz5zS-P8cB8D5yAQz1qTmDDcMI-lPNh+OEs8k+dASKkmPAlnE9OcjDqrkdCFzfngVodAESPzLngXaGADpEybqOM2U4PJznOnXL2UwtoYObpOVuDtNRID2M7Uiphh7FnZuRVB7Ue7nW1sYX2m8oDlWekgNG9VsZEJfo-c+l8UBoEhm0HYd8M7w0PmYdA6A0DvACnlGBcV3zkMocbYedclr-iQQtGhqBVJ7B7sPfRmVsrG2oYVPKJVuZ4zgJxNgRBQjAE1DVYAc1kE2w0cALa24pggBkseW2bduGoW2gnBAwIBwEOag9ceKdJwUNkQACToHwVx2iPHUT2J-YA25GK5OykQexjjnGcBMrVTAN1bEFIcU45oQ4qKyXiSgJJKSF4UD2LRQ0DFmKsQ4iZApuh1b5MKTUpiDivBAwKq9NACBsBwECOOBxUAJDsWEu0vMwAxISTfmE2ETZjCDitm4ta8VrowTWTQQSiFAJwFQgBTC2FjDGFyYxIZ1TimmTKRUuxbzalKWoZRNexgGkqOaQOP5XMMmPJeHRLpLE2LsT6WYPic5XlFOaMxd4MgJlwHYvMwpSy7zQHVpctAqyoU0FEuJJ8IQGqNJgKC8FKkYJktoE2XSbtDTwH8MkpKNK4B0uaduVZlBuV8EYh0DiSwVnCFFeKpAkqehyHVlJI8akKD6FWRyrQ7geVbllRKtC7EpUFXKPkRI7EMKrN+GKrJ24VX+PIBqmVyS5XbkNcanFpqEjpgtXOIVDqnWUCAA\n\n### 💻 Code\n\n```ts\r\nexport interface Update {\r\n update_id: number;\r\n\r\n message?: { message: string };\r\n edited_message?: { edited_message: string };\r\n channel_post?: { channel_post: string };\r\n edited_channel_post?: { edited_channel_post: string };\r\n message_reaction?: { message_reaction: string };\r\n message_reaction_count?: { message_reaction_count: string };\r\n inline_query?: { inline_query: string };\r\n chosen_inline_result?: { chosen_inline_result: string };\r\n callback_query?: { callback_query: string };\r\n shipping_query?: { shipping_query: string };\r\n pre_checkout_query?: { pre_checkout_query: string };\r\n poll?: { poll: string };\r\n poll_answer?: { poll_answer: string };\r\n my_chat_member?: { my_chat_member: string };\r\n chat_member?: { chat_member: string };\r\n chat_join_request?: { chat_join_request: string };\r\n chat_boost?: { chat_boost: string };\r\n removed_chat_boost?: { removed_chat_boost: string };\r\n}\r\n\r\ntype FilterFunction\u003cU extends Update, V extends U> = (up: U) => up is V;\r\n\r\nexport function matchFilter\u003cU extends Update, Q extends FilterQuery>(\r\n filter: Q | Q[],\r\n): FilterFunction\u003cU, Filter\u003cU, Q>> {\r\n // ^ errors out\r\n console.log(\"Matching\", filter);\r\n return (up: U): up is Filter\u003cU, Q> => !!up;\r\n}\r\n\r\n/** All valid filter queries (every update key except update_id) */\r\nexport type FilterQuery = keyof Omit\u003cUpdate, \"update_id\">;\r\n\r\n/** Narrow down an update object based on a filter query */\r\nexport type Filter\u003cU extends Update, Q extends FilterQuery> = PerformQuery\u003c\r\n U,\r\n RunQuery\u003cQ>\r\n>;\r\n\r\n// generate an object structure that can be intersected with updates to narrow them down\r\ntype RunQuery\u003cQ extends string> = Combine\u003cL1Fragment\u003cQ>, Q>;\r\n\r\n// maps each part of the filter query to Record\u003c\"key\", object>\r\ntype L1Fragment\u003cQ extends string> = Q extends unknown ? Record\u003cQ, object>\r\n : never;\r\n// define all other fields from query as keys with value `undefined`\r\ntype Combine\u003cU, K extends string> = U extends unknown\r\n ? U & Partial\u003cRecord\u003cExclude\u003cK, keyof U>, undefined>>\r\n : never;\r\n\r\n// apply a query result by intersecting it with update,\r\n// and then using these values to override the actual update\r\ntype PerformQuery\u003cU extends Update, R extends object> = R extends unknown\r\n ? FilteredEvent\u003cU, Update & R>\r\n : never;\r\n\r\n// narrow down an update by intersecting it with a different update\r\ntype FilteredEvent\u003cE extends Update, U extends Update> =\r\n & E\r\n & Omit\u003cU, \"update_id\">;\r\n\r\ntype Middleware\u003cU extends Update> = (ctx: U) => unknown | Promise\u003cunknown>;\r\nclass EventHub\u003cU extends Update> {\r\n use(...middleware: Array\u003cMiddleware\u003cU>>): EventHub\u003cU> {\r\n console.log(\"Adding\", middleware.length, \"generic handlers\");\r\n return this;\r\n }\r\n on\u003cQ extends FilterQuery>(\r\n filter: Q | Q[],\r\n ...middleware: Array\u003cMiddleware\u003cFilter\u003cU, Q>>>\r\n // ^ errors out\r\n ): EventHub\u003cFilter\u003cU, Q>> {\r\n console.log(\"Adding\", middleware.length, \"handlers for\", filter);\r\n return new EventHub\u003cFilter\u003cU, Q>>();\r\n }\r\n}\r\n```\r\n\n\n### 🙁 Actual behavior\n\nTypeScript compiler throws \"Expression produces a union type that is too complex to represent\" on `Filter` type instantiation with large interface\n\n### 🙂 Expected behavior\n\nTypeScript compiler shouldn't throw \"Expression produces a union type that is too complex to represent\" on `Filter` type instantiation with large interface\n\n### Additional information about the issue\n\nOn 5.3.3, such issue doesn't occur (even when we are adding more parameters to `Update` interface, e.g. additional 20-30 parameters)\r\nBut, on 5.4.2 it seems like limit for it is lowered down. When `chat_boost` and `removed_chat_boost` are removed, both `Filter` instantiations no longer throwing errors","author":{"url":"https://github.com/SecondThundeR","@type":"Person","name":"SecondThundeR"},"datePublished":"2024-03-20T10:22:19Z","url":"https://github.com/microsoft/TypeScript/issues/57863"}
| 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:21c5c802-45fb-b11b-1227-047c659968b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C16:3EA722:758B37:9C6116:6B04E90D |
| html-safe-nonce | 2f2476320367426ac1ce58444ef532ac2ed1f43525e0d106d0710cd441a7f427 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzE2OjNFQTcyMjo3NThCMzc6OUM2MTE2OjZCMDRFOTBEIiwidmlzaXRvcl9pZCI6IjE3NDM2MzgyODQ5MzI4MTU0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f3d4d162475a1901ca83b0976e48a4db474bf90d5c99debecd6502f02de44b03 |
| hovercard-subject-tag | issue:2197171816 |
| 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/57863/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5513c7e9d67e56d80e1c25fa6d44ecfe081276908cd75ef8151706411f5295dd/microsoft/TypeScript/issues/57863 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5513c7e9d67e56d80e1c25fa6d44ecfe081276908cd75ef8151706411f5295dd/microsoft/TypeScript/issues/57863 |
| og:image:alt | 🔎 Search Terms Expression produces a union type that is too complex to represent, 2590, ts2590 🕗 Version & Regression Information This behavior occurs in 5.4.2 and above. On 5.3.3 it works fine ⏯ P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SecondThundeR |
| hostname | github.com |
| expected-hostname | github.com |
| None | f3851aad500d8e8dce736722ddc6fa9596e17d9fce3c53581eba968664c0bc32 |
| 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 | e29c922455fd8137f27e1cfcdf6a1e8b920b1926 |
| 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