Title: Function cannot be contextually typed when its rest parameter type is tuple type with leading rest elements · Issue #45972 · microsoft/TypeScript · GitHub
Open Graph Title: Function cannot be contextually typed when its rest parameter type is tuple type with leading rest elements · Issue #45972 · microsoft/TypeScript
X Title: Function cannot be contextually typed when its rest parameter type is tuple type with leading rest elements · Issue #45972 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms function rest arguments parameter tuple type leading middle rest elements 🕗 Version & Regression Information 4.2.3, 4.3.5, 4.4.2 I was unable to test this on prior versions because leading rest elements in tuple...
Open Graph Description: Bug Report 🔎 Search Terms function rest arguments parameter tuple type leading middle rest elements 🕗 Version & Regression Information 4.2.3, 4.3.5, 4.4.2 I was unable to test this on prior version...
X Description: Bug Report 🔎 Search Terms function rest arguments parameter tuple type leading middle rest elements 🕗 Version & Regression Information 4.2.3, 4.3.5, 4.4.2 I was unable to test this on prior ver...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/45972
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function cannot be contextually typed when its rest parameter type is tuple type with leading rest elements","articleBody":"# Bug Report\r\n\r\n\r\n### 🔎 Search Terms\r\n\r\nfunction rest arguments parameter tuple type leading middle rest elements\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n4.2.3, 4.3.5, 4.4.2\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- I was unable to test this on prior versions because _leading rest elements in tuple types were introduced in TS 4.2_\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.4.2#code/C4TwDgpgBAYgrgOwMZQLxQBQDocEMBOA5gM4BcUA2jlscPmVLfgJYKEUC6ANFAnALYBGcn34AjCPh6iATCIET8HAJRoAfFABuAe2YATAFAGA9MagB5ANIGk2hLSgAzREnLxkaTKtQaA3gF8TMwBRfHxtfFIgqAAVcGgAcgwCQmFGOlZCKAAfXgVJbw0dfQSoZmJebWAoXGJiZkIEXDEAG2hgbShQSCgE9yQErGjY+IrtRygwAlx+CGBJCoSUwVLcBD1epmJV-GhWW34p4GZWiCHTKEuRnoSqHC3yJkzOaQE00UVX-jk88UkOUrlSrVWr1RrNNpdTrdRIUZaPDJsHK-RQA85mK6XADK2jg+CQ0AAFrUoDIoBA2rMEMAMMRVGI4NVgCk5jUWi1tAB3MYIFogKCCIa2ezVZzINL9TzJIiCQpQAJGC6hcKRaJxG7Swg-J5I3IfSQ8FIAZgRLF1KIK6i0uj0gIqCCqNTqDSapyhXXivX6g2G1wgYwmU3wMzmC16KRkq3Wmzo2xquzKyG0h1wx1O6Mxft6dxosdNz24v3e+Skvx++qUduBTrBrshHQ9NzhRG1iKyepLhqIJvSZvbFsrGczsRZIPZXJ5fNJ5MpEGptPpjMYuPx0H4uH5xM0a4iZxsdgcYqQP0l6E1Mi7hCNcoCAG5FSEwhEohd1YlNQAWfPmiuXgCs379r+8aEAAbIByIVnKxS2mU9qOqCLoQu00Ken0Lg+hclxvgGkzTLM8z0OGRAflGGwJFsOx7EmKZpm0Q5XG+2bUA8vYFl8xZ-KWsjyFxAJwdWiHgm6DYwtmKRfmxP6diBAFSUBMkpOB8mQSWaK+piMSjlAuwAI5wMwuwVEaM4QFSNJ0lADLVMQK4ElA66brg25OBAnKSEKB6ii4PanpgEn-peoE3v494GEAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype Func = (...args: [...strs: string[], num1: number, num2: number]) => void\r\n\r\n// OK\r\nconst func: Func = () => {}\r\n// Error:\r\n// Type '(arg1: string | number) => void' is not assignable to type 'Func'.\r\n// Types of parameters 'arg1' and 'strs' are incompatible.\r\n// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg1: string | number]'.\r\n// Source has 2 element(s) but target allows only 1.\r\nconst func1: Func = (arg1) => {}\r\n\r\n// Error:\r\n// Type '(arg2: string | number, arg3: string | number) => void' is not assignable to type 'Func'.\r\n// Types of parameters 'arg2' and 'strs' are incompatible.\r\n// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg2: string | number, arg3: string | number]'.\r\n// Target allows only 2 element(s) but source may have more.\r\nconst func2: Func = (arg2, arg3) => {};\r\n\r\n// Error:\r\n// Type '(arg4: string | number, arg5: string | number, arg6: string | number) => void' is not assignable to type 'Func'.\r\n// Types of parameters 'arg4' and 'strs' are incompatible.\r\n// Type '[...strs: string[], num1: number, num2: number]' is not assignable to type '[arg4: string | number, arg5: string | number, arg6: string | number]'.\r\n// Target requires 3 element(s) but source may have fewer.\r\nconst func3: Func = (arg4, arg5, arg6) => {};\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nFunctions that have one or more arguments (`func1`, `func2`, `func3`) cannot be assigned to variables of type `Func`.\r\n\r\n### 🙂 Expected behavior\r\n\r\nNo compiler errors and the types of arguments are inferred as:\r\n\r\n- `arg1`, `arg2`, `arg3`, `arg4`, `arg5`: `string | number`\r\n- `arg6`: `string | number | undefined`\r\n","author":{"url":"https://github.com/uhyo","@type":"Person","name":"uhyo"},"datePublished":"2021-09-20T17:07:58Z","url":"https://github.com/microsoft/TypeScript/issues/45972"}
| 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:7dab9272-73f3-7f30-2871-0aee4a4a7018 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB8A:519AB:113DE4:189486:6B0464C6 |
| html-safe-nonce | 2e6ab2e35ac7f93288aea167b5db3042baf55e520853bbc4ec82b342e70ce7db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjhBOjUxOUFCOjExM0RFNDoxODk0ODY6NkIwNDY0QzYiLCJ2aXNpdG9yX2lkIjoiMTY4MDE2Nzg3MzQzMzMzMDg4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd51f12c79363542b294c304b17d053fff130dc7e87ff2d6d8ae53ff38db5acf |
| hovercard-subject-tag | issue:1001201252 |
| 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/45972/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e75ee8181ffe9a6dfedcd37a8a22bd475678a3051185a6a3d5b3af4b54b41db4/microsoft/TypeScript/issues/45972 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e75ee8181ffe9a6dfedcd37a8a22bd475678a3051185a6a3d5b3af4b54b41db4/microsoft/TypeScript/issues/45972 |
| og:image:alt | Bug Report 🔎 Search Terms function rest arguments parameter tuple type leading middle rest elements 🕗 Version & Regression Information 4.2.3, 4.3.5, 4.4.2 I was unable to test this on prior version... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | uhyo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | canary-2 |
| 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