TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms: rest parameters inline type destructure error
Code
function foo(...[a, b]) {
return a + b;
}
Expected behavior:
The code is valid JavaScript and should compile without errors.
Actual behavior:
It errors:
index.ts:1:17 - error TS2501: A rest element cannot contain a binding pattern.
Why would you want to destructure rest params like this? In order to use Parameters<T> to type the parameters based on another function:
function foo(a: string, b: number) {}
function bar(...[a, b]: Parameters<typeof foo>) {}
Playground Link: https://www.typescriptlang.org/play/index.html#src=function%20foo(...%5Ba%2C%20b%5D)%20%7B%0D%0A%20%20%20%20return%20a%20%2B%20b%3B%0D%0A%7D%0D%0A
Related Issues:
TypeScript Version: 3.3.0-dev.201xxxxx
Search Terms: rest parameters inline type destructure error
Code
Expected behavior:
The code is valid JavaScript and should compile without errors.
Actual behavior:
It errors:
Why would you want to destructure rest params like this? In order to use
Parameters<T>to type the parameters based on another function:Playground Link: https://www.typescriptlang.org/play/index.html#src=function%20foo(...%5Ba%2C%20b%5D)%20%7B%0D%0A%20%20%20%20return%20a%20%2B%20b%3B%0D%0A%7D%0D%0A
Related Issues: