Title: Callback parameter inference not working when part of an inferred tuple type · Issue #52047 · microsoft/TypeScript · GitHub
Open Graph Title: Callback parameter inference not working when part of an inferred tuple type · Issue #52047 · microsoft/TypeScript
X Title: Callback parameter inference not working when part of an inferred tuple type · Issue #52047 · microsoft/TypeScript
Description: Bug Report Been experiencing the below problem with no-implicit-any on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring. Was thinking it could be a case of unsupported/incorrect ...
Open Graph Description: Bug Report Been experiencing the below problem with no-implicit-any on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring. Was thinking it c...
X Description: Bug Report Been experiencing the below problem with no-implicit-any on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring. Was thinking it c...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52047
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Callback parameter inference not working when part of an inferred tuple type","articleBody":"# Bug Report\r\n\r\nBeen experiencing the below problem with `no-implicit-any` on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring.\r\n\r\nWas thinking it could be a case of unsupported/incorrect usage on my end, however the type suggestion does appear to be correct on-mouse-hover, so wondering if there's something extra at play.\r\n\r\nMight be somewhat related to https://github.com/microsoft/TypeScript/issues/44476 but not sure.\r\n\r\n### 🔎 Search Terms\r\n\r\nTuple, callback, generic, inference\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\nThis is the behavior in every version I tried since 4.0 that brought support for variadic tuples, and I reviewed the FAQ for entries about generics/tuples/callbacks\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.0-dev.20221229#code/C4TwDgpgBA8mwEsD2A7AzgHgCpQLxQFcUBrFJAdxQD48oBvAKCigRTAOABEBDYbgLihYA3EygALbigAmAGwgAnQQApggrAEo8NAG5IE0hgF8GDAGZEAxolRQzSJAHUEwcQElgEALbZaRUhTUygBG3Eqw8Mjo2FRajMwKEMAECijGpgD0GVAACtxoaBBoUKCQALSW4hCWxFD5UBAAHpDWEIb2Ti7unl7K8SxsHDx8ggDkaMAKrADmowA0YpIy8uHKjYITUyjTWrg0dCZGGpnZAGLcCLLFpRAVVTV1xU0tnu0Ozq4e3n1irOxcvAEUHGkxm80WUjkihU6ygKAIXmCil2+0OxxOUAAgsF5CUkAMzIpHg1mtVXuZ3l0vr1+n8hoCxpswQtmEsoatGij6GjTDcoABReReOA2aJYGj4HBNTwyYp0Ab-YZA1iEhRQAAaUCMUAA-BFRZh1TRBCgIDpFLzwNAsAQwPIRVFMGIpY0ZdJilIQABtAC6CwlQhJbuKXpVRMF3h9Yj1XojwsiqEwcaoUeY6lMFhQ1iidkprhtdogvmlEFldRQ3p9VBCYUEiW40lQshAUC9ADoOwX7QmxSm4mJEslUukGFlcvlCtcrXdqrV6s8yW0KZ187b5MovbTBgCRsCmdtwazISsYRtQdsuQdjD70WPzpcp+VKrPiQvWm8V+IuxAN1vFQy93PWYWQkY9oSgNYTQRJEFEvQ4b1MUdsgACQoM0iSIbgcWgYB8TDBRlw+L81x-Tdfm3JVGSAw8oDHPIFG4LwkiJUZGlGFgvDtBBLBcZtQI9FBgU9dibjbMQx3QwTXCQAhpnECQkHNLZpigRSiQAAzZFZ1KgSwkAURJrD42QsIgK4WGAYlNLA1Y1Cgfcdm0KA9AMdSIWWcC1jg69jiAA)\r\n\r\n(for context, if the above example feels a bit contrived: the actual use-case involves typing/checking a function argument that can be a variadic tuple with multiple complex elements, using a more complex utility type. If interested [here's a second playground link](https://www.typescriptlang.org/play?#code/C4TwDgpgBA8mwEsD2A7AzgHgCpQLxQFcUBrFJAdxQBooBVPQksygPgYG8AoKKBFMAsAAiAQ2AiAjAC4oWANzcoACxEoAJgBsIAJxkAKYDKwBKPGwBuSBGsV8BwsSIBMAfhm0FAX06cAZkQBjRFQoXyQkAHUEYCUASWAIAFtsGloWPQAjEV1YeGR0FLoWUy4ebQhgAm0UTm9OAHp6qAAFETQ0CDQoUEgAWgClCADiKDaoCAAPSCCIGzDI6LiExL1S3n5BUXFpKAByNGBtPgBzXapFFXUtHL0JmQOjlGPTXDZ2b09jH0aoADERBAaLo9CD9QbDUZdSbTBJzcJRGLxJKrWwbBzbGT7Q4nM4XVSaHT6O5QFAERIZHQvN4fL7fJoAQQyWm6SHWvh0kPGUyGsL88MWSJWazsm0cOyxj1O5x4lwJNwmVKg71qtJBUAAolpEnBggUsGx8DhJgl1F0dflMHx2dooAANGhWjkATTYLlyusw9qgLqgMhQEHMOh8aqwBDAWnNqEwiiNExNai6qhAAG0ALrSqAAJU6BA0wC58cTKBTqYYafOBtkBYgpqgacUbvrPCM1drycdNoAEhARGpUw26wA6YfZtC54A0TVJSMFbu9lj95tV401hN1jtQOdqGjDwcbrAAjSLqBu0PhiAzzDJ3cHwHpocjnN5yday8YLcLliKIw+fwoIL5KE-IxGeWjYK2a5Jmm6RZDk5S9qgGggA+g6gReeRRtgC4lIo5SVNUtR0i0bQdMC4CggMQwjGM0I8rMfILCBYZaHoybCmiWySJiDw4hmsrXES9zYk8irKp4qa0j8-yAmRfSURCNHcjMcKMUoaGsex9iceKPFPLiMr4gJUC3H6ZIUtookfBJPgNE0nYUAGHJECITLQMArIdgxCJqcxEAaaiWlitxwlSooPytNoIiJBUHK7BMuy8Ik4YIAE0RIcoYyqHsSYJSCg5hU0jkoN0ShIAQxxKMoSCBpKUDVRyAAG-E6A1UABEg2jlEE6UaC5EBArw+ZjE1hmEsZhhQLpzxmFAljWA1eJXGNtyWbU1lAA) with the whole shebang - but in the first one I've tried to pare it down to the most basic example with just 1 element on the tuple)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well--\u003e\r\n```ts\r\n\r\ntype Options\u003cT = unknown\u003e = {\r\n inputData: T;\r\n handler: (t: T) =\u003e void\r\n}\r\n\r\ntype ElemOptions\u003cT\u003e = T extends { inputData: infer X } ? Options\u003cX\u003e : never\r\n\r\ntype TupleOptions\u003c\r\n T extends any[],\r\n\u003e = T extends [infer Elem]\r\n ? [ElemOptions\u003cElem\u003e]\r\n : T\r\n \r\nfunction fooWithTuple\u003cT extends any[]\u003e(bar: readonly [...TupleOptions\u003cT\u003e]) {\r\n return\r\n}\r\n\r\nfooWithTuple([{\r\n inputData: 'string',\r\n // Error: Parameter 'x' implicitly has an 'any' type.\r\n // even though hovering over `handler` correctly labels it as `handler: (t: string) =\u003e void`\r\n handler: (x) =\u003e {}\r\n}])\r\n\r\n// included in the playground link but not shown here:\r\n// (1) type-inference all works fine when you're not dealing with a tuple, and\r\n// (2) type-checking in a tuple works correctly when you add the param type explicitly\r\n\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nHandler complains about no-implicit-any, even though type-suggestion work as expected, and type-checking works if you add the param type explicitly.\r\n\r\n### 🙂 Expected behavior\r\n\r\nHandler parameter type can be inferred automatically; no no-implicit-any complaints.\r\n","author":{"url":"https://github.com/artysidorenko","@type":"Person","name":"artysidorenko"},"datePublished":"2022-12-29T16:24:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/52047/TypeScript/issues/52047"}
| 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:61a2c492-f865-aeb3-d40f-eb40565c70d3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A880:564E7:8A9DC:BF31B:6A622D99 |
| html-safe-nonce | fa8f969d27a1c6874f54cdad5665a8f9acb4c4cfcff4953f0097642687cd0be7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODgwOjU2NEU3OjhBOURDOkJGMzFCOjZBNjIyRDk5IiwidmlzaXRvcl9pZCI6IjkxODI2MzYyNzUyOTE3OTQ4NDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6ed6c4cacd46b82669cb21b33ef544c29446b9231422c56f7ffb99981ecf9d21 |
| hovercard-subject-tag | issue:1513879268 |
| 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/52047/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fbb20c60a2bf8442abc7de9e221860d8a4f7a55041dcac55e0116dea019cec70/microsoft/TypeScript/issues/52047 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fbb20c60a2bf8442abc7de9e221860d8a4f7a55041dcac55e0116dea019cec70/microsoft/TypeScript/issues/52047 |
| og:image:alt | Bug Report Been experiencing the below problem with no-implicit-any on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring. Was thinking it c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | artysidorenko |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0e882415c7b47986d65f899389c870b31642bb1c6f36516eb042618596c60e62 |
| 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 | 230e2af5fc0870303dd4569d72d2bb393ed52c52 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width