Title: Function inference fails when a final argument is supplied after rest via destructured tuples · Issue #43122 · microsoft/TypeScript · GitHub
Open Graph Title: Function inference fails when a final argument is supplied after rest via destructured tuples · Issue #43122 · microsoft/TypeScript
X Title: Function inference fails when a final argument is supplied after rest via destructured tuples · Issue #43122 · microsoft/TypeScript
Description: Bug Report I'm not sure whether inference failures are usually classified as suggestions or bugs. Sorry if I've assigned this the wrong label! 📖 Context / Introduction I'm trying to improve the typings for an open source library called r...
Open Graph Description: Bug Report I'm not sure whether inference failures are usually classified as suggestions or bugs. Sorry if I've assigned this the wrong label! 📖 Context / Introduction I'm trying to improve the typ...
X Description: Bug Report I'm not sure whether inference failures are usually classified as suggestions or bugs. Sorry if I've assigned this the wrong label! 📖 Context / Introduction I'm trying to imp...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/43122
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function inference fails when a final argument is supplied after rest via destructured tuples","articleBody":"# Bug Report\r\n\r\nI'm not sure whether inference failures are usually classified as suggestions or bugs. Sorry if I've assigned this the wrong label!\r\n\r\n### 📖 Context / Introduction\r\n\r\nI'm trying to improve the typings for an open source library called [reselect](https://github.com/reduxjs/reselect). Their `createSelector` function first takes in an arbitrary amount of \"selector\" functions that take in one parameter as a given state type, and then takes in one final additional function which combines the results of the previous functions. I have an implementation, but inference isn't working as I expect.\r\n\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?ts=4.2.2#code/KYDwDg9gTgLgBDAnmYcDKwA2wDGNoA8aMAhjMAHxwC8cAFAM6nkBc6zwAlDVQK4B2Aa34QA7vwDcAKFCRYCZKgzY80ACq8w2Ihyq1lufFB1lKAbQC60meGjwkKOAFEQJALZbgxUzTgBvKTg4ADMICDYAIlCICOkggCMSKDYAFgAmaQBfa1k7EIE8AEsIfjgcKGBTA1VjNDhQcn4AEwZ0LEN1TW0Xd09vcgoKOkC4ADpxhnaahjYzcdHJlSMZ9AAaELY6EDYSfkRuaipdxAs4AHozkLKSXknWwoYGXmAGKW4AoJwShghsUcwIABzRhTZacLJSKTlSrkapGYZBLYHKggUbRdYXOAgOAPOAQYJwADkx0JCkcUDIAAtgFAEJTds5XB5sP1gCMkTwsaNElAMZdsbj8USSWTUBSYNTaRKGT1mV4OOzkXB0m9pEA)\r\n\r\n### 💻 Code\r\n```ts\r\nexport type Selector\u003cState> = (state: State) => unknown;\r\nexport type SelectorTuple\u003cState> = Selector\u003cState>[];\r\n\r\nexport type ExampleState = {\r\n foo: \"foo\";\r\n bar: 42;\r\n};\r\n\r\nexport function createSelector\u003cS extends SelectorTuple\u003cExampleState>>(\r\n ...selectors: [...selectors: S, f: (x: any) => any] // f causes issues\r\n) {\r\n console.log(selectors);\r\n}\r\n\r\ncreateSelector(\r\n (x) => x.foo, // x is of 'any' type rather than ExampleState\r\n (x) => x.bar, // x is of 'any' type rather than ExampleState\r\n () => 42\r\n);\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nIn the `createSelector` call, all of the `x` parameters have an implicit type of `any`, instead of `ExampleState`.\r\n\r\nObservations:\r\n* When the last tuple element is removed from the type, inference works.\r\n* When the last tuple element is made to have zero parameters, inference works.\r\n* When the last tuple element is made to be anything except a function or `any`, inference works.\r\n\r\nFor some reason, the compiler is having difficulty inferring the rest parameters in this case.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI would expect the type system to infer that the `x` parameter of all functions except the last is `ExampleState`.","author":{"url":"https://github.com/poteat","@type":"Person","name":"poteat"},"datePublished":"2021-03-07T00:18:57Z","url":"https://github.com/microsoft/TypeScript/issues/43122"}
| 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:92be002a-d4f9-7968-303b-d8c74d075393 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D886:317608:27C661E:32556D7:6B019461 |
| html-safe-nonce | d2ec65fee095da918b6d1ed75e6a916725ec066d3717ac708c2cc902a6cb3d6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODg2OjMxNzYwODoyN0M2NjFFOjMyNTU2RDc6NkIwMTk0NjEiLCJ2aXNpdG9yX2lkIjoiNzY2ODEzNzkwNTU2NzU1MDQxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3668dd8e3bc24f28b0f9a6456252dfa74a9db67614aebdc52f3b0cae0d7c1e85 |
| hovercard-subject-tag | issue:823786295 |
| 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/43122/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1eab868dcb57cbfbde891b48b8a6165077a355d8b65577ecf0f8a89cef502ee1/microsoft/TypeScript/issues/43122 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1eab868dcb57cbfbde891b48b8a6165077a355d8b65577ecf0f8a89cef502ee1/microsoft/TypeScript/issues/43122 |
| og:image:alt | Bug Report I'm not sure whether inference failures are usually classified as suggestions or bugs. Sorry if I've assigned this the wrong label! 📖 Context / Introduction I'm trying to improve the typ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | poteat |
| 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