Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest parameter does not play well with generic array #16931

Closed
amir-arad opened this issue Jul 4, 2017 · 3 comments
Closed

rest parameter does not play well with generic array #16931

amir-arad opened this issue Jul 4, 2017 · 3 comments

Comments

@amir-arad
Copy link

amir-arad commented Jul 4, 2017

TypeScript Version: 2.3.4

Code

//  error, defined as ???
type Method<A extends Array<any>, R = void> = (...args: A) => R;

// this is still passed
const foo: Method<[number, string], string> = (a: string, b: number) => a + b;
//                 ^^^^^^  ^^^^^^              ^          ^

Expected behavior:
pass validation
Actual behavior:
Error:(1, 47) TS2370:A rest parameter must be of an array type.

@amir-arad
Copy link
Author

amir-arad commented Jul 4, 2017

my current replacement solution is:

 type Method<R = void> = (...args:any[]) => R;
 type Method0<R = void> = () => R;
 type Method1<T1, R = void> = (t1: T1) => R;
 type Method2<T1, T2, R = void> = (t1: T1, t2: T2) => R;
 type Method3<T1, T2, T3, R = void> = (t1: T1, t2: T2, t3: T3) => R;
 type Method4<T1, T2, T3, T4, R = void> = (t1: T1, t2: T2, t3: T3, t4: T4) => R;

@ikatyang
Copy link
Contributor

ikatyang commented Jul 5, 2017

It seems duplicate of #5331 and #5453?

Edit:

//  error, defined as ???
type Method<A extends Array<any>, R = void> = (...args: A) => R;

// this is still passed
const foo: Method<[number, string], string> = (a: string, b: number) => a + b;
//                 ^^^^^^  ^^^^^^              ^          ^

@amir-arad
Copy link
Author

thanks for the edit @ikatyang . seems like a duplicate indeed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants