Title: Remapping a tuple constraint fails to provide a contextual type for the tuple elements · Issue #52650 · microsoft/TypeScript · GitHub
Open Graph Title: Remapping a tuple constraint fails to provide a contextual type for the tuple elements · Issue #52650 · microsoft/TypeScript
X Title: Remapping a tuple constraint fails to provide a contextual type for the tuple elements · Issue #52650 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms tuple constraint infer type parameter remapped reverse mapped contextual type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground Link Playground link with relevant code...
Open Graph Description: Bug Report 🔎 Search Terms tuple constraint infer type parameter remapped reverse mapped contextual type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground...
X Description: Bug Report 🔎 Search Terms tuple constraint infer type parameter remapped reverse mapped contextual type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playgr...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52650
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Remapping a tuple constraint fails to provide a contextual type for the tuple elements","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\ntuple constraint infer type parameter remapped reverse mapped contextual type\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.9.5#code/C4TwDgpgBAKgrmANhAPDAfFAvFAThAQwBMB7AO0RCgG0YAaKAOmZmoF02BuAKG6IgDGiAvigAzOGQHAAluSgAjGWSIBBRIhTcosGCIDmEYFAgAPYBBUBnKAFEAbpeB7ch4HW27wEG2YvXYBGQUAGsIEBIxXQMjKAAyKAADcgASAG8CMhAAX0T0bnQACk9gGOAALmjXIw8dJRVlfStKtM8dagBpKGUoMIiomBhvKzYWtp0oUEhKweHOrnGdRBkrfwhcSuKJ7ZN7SoAFEQIAWyN1qxRbc1wCaTQXN1ohyCt5tgZC5kYDZqhMkHYAEpsJh-uh0NQAAxsRZQYFYTD2EgyIg8bbZNFQbLcQGVJEonjcepqDSFNLZP42AASMAAsgAZABCcGAwHItmQpzI7honla2ymEEqACJyEIZAIQsLahNlqtLOtNhBHNz4Zh+TtlU5YQB6HVQAB6AH5xtkZWa+eNBSLyH1SAB3MjS8ZytYbKCFLWqkFQDXbL3AXX642m80eNiAnhAA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype Tuple\u003cT> = readonly [T, ...T[]];\r\n\r\ndeclare function bindAll\u003c\r\n TTarget extends EventTarget,\r\n TTypes extends Tuple\u003ckeyof TTarget & `on${any}`>\r\n>(\r\n target: TTarget,\r\n bindings: {\r\n [K in keyof TTypes]: {\r\n type: TTypes[K];\r\n listener: (\r\n ev: Parameters\u003cExtract\u003cTTarget[TTypes[K]], (...args: any[]) => any>>[0]\r\n ) => void;\r\n };\r\n }\r\n): void;\r\n\r\nbindAll({} as HTMLButtonElement, [\r\n {\r\n type: \"onclick\",\r\n listener: (event) => {\r\n event\r\n // ^? actual: string | Event | MouseEvent | ..., expected: MouseEvent\r\n },\r\n },\r\n {\r\n type: \"onkeydown\",\r\n listener: (event) => {\r\n event\r\n // ^? actual: string | Event | MouseEvent | ..., expected: KeyboardEvent\r\n },\r\n },\r\n]);\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nIt should be possible to provide per element types using reverse mapped types when mapping over a type parameter with a tuple constraint. It works OK when at the argument position we use `[...{ [K in keyof TTypes]: { /*...*/ } }]` instead of `{ [K in keyof TTypes]: { /*...*/ } }`. That is a weird workaround though.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI would expect the contextual types to be correctly provided for each element separately, just like in the case of `[...{ [K in keyof TTypes]: { /*...*/ } }]` ([TS playground](https://www.typescriptlang.org/play?ts=4.9.5#code/C4TwDgpgBAKgrmANhAPDAfFAvFAThAQwBMB7AO0RCgG0YAaKAOmZmoF02BuAKG6IgDGiAvigAzOGQHAAluSgAjGWSIBBRIhTcosGCIDmEYFAgAPYBBUBnKAFEAbpeB7ch4HW27wEG2YvXYBGQUAGsIEBIxXQMjKAAyKAADcgASAG8CMhAAX0T0bnQACk9gGOAALmjXIw8dJRVlfStK6k8dZkY0tp0aAGkoZSgwiKiYGG8rNkquntmoUEhKsYnqXq5u2cQZK38IXEriubmIe0qABRECAFsjPastI6Pbc1wCaTQXN1pxyCtVjgYhQ6BmaUEyIHYAEpsJhwflHj10NQAAxsDY9aFYTD2EgyIg8I7ZAk9bKeNGQyo4vE8bj1NQaQppbJgmwACRgAFkADIAITgwGA5FsyBuZHcNE8Mx6CwglQAROQhDIBCE5bUelsdpY9gcTk5MZgpbM9WL0QB6M1QAB6AH5utl1Q7Jd0ZfLyMNSAB3Mhq7qa3b7KCFE3AA1QI09EPmy22+2OjxsSE8IA))\r\n","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2023-02-07T09:15:20Z","url":"https://github.com/microsoft/TypeScript/issues/52650"}
| 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:251b2e8f-832f-a14a-f986-f16d79edb3ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E132:240CD1:276C171:321869D:6B019A3F |
| html-safe-nonce | cac3827bca57ea52ab2d6094746a3d26ee2e7a3bf86a542bf98ce0909775c008 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTMyOjI0MENEMToyNzZDMTcxOjMyMTg2OUQ6NkIwMTlBM0YiLCJ2aXNpdG9yX2lkIjoiMjYyMzQ2NzQzODk1OTg2MDI4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e55e15991299638d10dae6518fb46319df53fb082168f147bcc96ac67e5d9866 |
| hovercard-subject-tag | issue:1573960834 |
| 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/52650/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3d5c1811a145cf6efe50bb979b9436e2bfb9009396147ae674e02f0a0b1708dc/microsoft/TypeScript/issues/52650 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3d5c1811a145cf6efe50bb979b9436e2bfb9009396147ae674e02f0a0b1708dc/microsoft/TypeScript/issues/52650 |
| og:image:alt | Bug Report 🔎 Search Terms tuple constraint infer type parameter remapped reverse mapped contextual type 🕗 Version & Regression Information This is the behavior in every version I tried ⏯ Playground... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andarist |
| 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