Title: Missing reduction step in a union of intersections with bounded type parameter · Issue #48718 · microsoft/TypeScript · GitHub
Open Graph Title: Missing reduction step in a union of intersections with bounded type parameter · Issue #48718 · microsoft/TypeScript
X Title: Missing reduction step in a union of intersections with bounded type parameter · Issue #48718 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms reduction, generic, union, intersection 🕗 Version & Regression Information This bug is also the 'Nightly' version. Versions prior to 4.6.2 give even more errors. ⏯ Playground Link Playground link with relevant c...
Open Graph Description: Bug Report 🔎 Search Terms reduction, generic, union, intersection 🕗 Version & Regression Information This bug is also the 'Nightly' version. Versions prior to 4.6.2 give even more errors. ⏯ Playgro...
X Description: Bug Report 🔎 Search Terms reduction, generic, union, intersection 🕗 Version & Regression Information This bug is also the 'Nightly' version. Versions prior to 4.6.2 give even more error...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48718
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Missing reduction step in a union of intersections with bounded type parameter","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nreduction, generic, union, intersection \r\n\r\n### 🕗 Version & Regression Information\r\n\r\nThis bug is also the 'Nightly' version. Versions prior to `4.6.2` give even more errors.\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?target=9&jsx=0&ts=4.7.0-dev.20220415&ssl=27&ssc=3&pln=1&pc=1#code/C4TwDgpgBAcgrgWwgJwJYGMAyrgoIYA2UAvFAN4BQUUAboXBAFxQB2iARigNxVSiTMARPCRosOfAUE8Avj37QAysDQsA5tlzJCJcrzoEGzAM4rU6ntQVDlqjRO1TZ88NACSAEwgtgqAGaoKLqU1Cx4SCZmFrzWUIKe3r4BKNIUchQKUADChAQAogAeYMgQxsaoAPYswbxhEVCmdpZQeMhqiInGzAAiyBVgnK0wFV4A2gC6zbGCOQT5RSVllSyp6RmuUL39g8jDXiS8AD6wHWKakkdQtub2WoSXCT7+gciXs-PFpeVVPOuQUAA1VDlYAVZA1aijADSUHMmz6AwgQxGEFGggUgnG42YAAoWCjmIUVHh0MAADxbRHIrwAGnIfFczBhMgAfABKEgs2gVVAeNK-PxwFik5a0YE4PYQMkwiAFXAsDzGeHbJG7FGjADkCg14xZeIJUCJ2lJFIRO0ldLIDIEUGZLLpNGYQJBYI5IWo6CqploYF0NFG+K8ADpMnglVDxrwoAB6aPUagAPQA-FGaGB9V42WkKBRBcLfFUxSDJQAVUrkmVy7yK5VUtVjLWuHV6wNMQ1y43kynmlGW61tu0Op3i0HIN1RqOZUsbUg4hQVPysFEh1xZ+Ox+NQZNR2M7uNqVA0bx8AAWeGAtqgsvlNe7qslmu1410wlOGHOjkEUGOgmu6g-hBfj+jxJC8QFxO8hSfEsVSCHusAoiWGzGCeFRwAQHhQJwp7QMY4TQKG4Y5vGnosN6aZ+gGy4KJG65xvG27xmmGYQFmMg5kAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype NumericLiteral = {\r\n value: number;\r\n type: \"NumericLiteral\";\r\n};\r\ntype StringLiteral = {\r\n value: string;\r\n type: \"StringLiteral\";\r\n};\r\ntype Identifier = {\r\n name: string;\r\n type: \"Identifier\";\r\n};\r\ntype CallExpression = {\r\n name: string;\r\n arguments: DropbearNode[];\r\n type: \"CallExpression\";\r\n};\r\n\r\ntype DropbearNode =\r\n | NumericLiteral\r\n | StringLiteral\r\n | Identifier\r\n | CallExpression;\r\n\r\ntype Visitor = {\r\n [K in DropbearNode[\"type\"]]: (node: Extract\u003cDropbearNode, { type: K }>) => void\r\n};\r\n\r\nfunction visitNode\u003cK extends DropbearNode['type']>(node: Extract\u003cDropbearNode, { type: K }>, v: Visitor) {\r\n v[node.type](node) // error\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n`typeof node.type` is inferred as `(K & \"NumericLiteral\") | (K & \"StringLiteral\") | (K & \"Identifier\") | (K & \"CallExpression\")` that it is equal to `K` itself considering that `K extends \"NumericLiteral\" | \"StringLiteral\" | \"Identifier\" | \"CallExpression\"`.\r\nSomething goes really wrong when I try to use `node.type` as an index, maybe because its type doesn't perform well if used as an index to access the `Visitor` type.\r\n\r\n### 🙂 Expected behavior\r\n\r\n`typeof node.type` inferred as `K` because it is simpler to interact with and doesn't give problems if used as an index.\r\n","author":{"url":"https://github.com/jfet97","@type":"Person","name":"jfet97"},"datePublished":"2022-04-15T14:15:29Z","url":"https://github.com/microsoft/TypeScript/issues/48718"}
| 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:bc9ee0d5-5730-2057-8824-efc03e32fc73 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D66C:3F9CD1:116F9D9:16ACC71:6B04F3C4 |
| html-safe-nonce | 4e3c9abf387f82fde0d26724c009718e6b0c9e521af47580da79b493d1cb990c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjZDOjNGOUNEMToxMTZGOUQ5OjE2QUNDNzE6NkIwNEYzQzQiLCJ2aXNpdG9yX2lkIjoiOTI1NjQyNjQ3NTMwNjk3NjY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4368d478d1bcc46eb02de3d59524e36bb2e1e3121882d9f183e279104f49c20e |
| hovercard-subject-tag | issue:1205612611 |
| 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/48718/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f76ae061d6d698ce02d6b928764afac04fca6fb038c3ac2966edfb15ccdca01f/microsoft/TypeScript/issues/48718 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f76ae061d6d698ce02d6b928764afac04fca6fb038c3ac2966edfb15ccdca01f/microsoft/TypeScript/issues/48718 |
| og:image:alt | Bug Report 🔎 Search Terms reduction, generic, union, intersection 🕗 Version & Regression Information This bug is also the 'Nightly' version. Versions prior to 4.6.2 give even more errors. ⏯ Playgro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jfet97 |
| 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