Skip to content

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

Closed

Description

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

Activity

  1. mhegazy commented on Apr 16, 2018

    @mhegazy
    Contributor

    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.

  2. added
    DuplicateAn existing issue was already created
    and removed
    DuplicateAn existing issue was already created
    on Apr 16, 2018
  3. typescript-bot commented on May 1, 2018

    @typescript-bot
    Contributor

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

  4. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions