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

A rest parameter must be of an array type. #23440

Closed
TheColorRed opened this issue Apr 16, 2018 · 2 comments
Closed

A rest parameter must be of an array type. #23440

TheColorRed opened this issue Apr 16, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@TheColorRed
Copy link

TheColorRed commented Apr 16, 2018

When running a rest type with multiple array types an error is thrown. Using (xx | yy)[] works however that is not always desired, due to the fact that it allows for mixing types in one array, and not two different types of arrays.

TypeScript Version: 2.8.1

Code

function dist(x1: number, y1: number, x2: number, y2: number): number
function dist(point1: point, point2: point): number
function dist(...args: number[] | point[]): number {
  // function body
}

Expected behavior:

...args should not throw an error

Actual behavior:

The following error is thrown

A rest parameter must be of an array type.

Playground Link:

Playground

@mhegazy
Copy link
Contributor

mhegazy commented Apr 16, 2018

I think this is another manifestation to the same underlying issue as #15972. the compiler checks if the type of the rest parameter is just the "Array" type.

I would suggest moving this to #15972.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Duplicate An existing issue was already created labels Apr 16, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants