Skip to content

Trailing comma in tuple after rest #35375

Closed

Description

Search Terms: Trailing comma tuple

Code

var [...x]: [...string[]] = [];
var [...x,]: [...string[]] = [];
var [...x]: [...string[],] = [];

Actual/Expected behavior:

Currently, the first line is valid, the second line is invalid because a rest element can't be followed by a trailing comma, and the third line is considered as valid by TypeScript.

I think that for symmetry with array and object rest elements, also rest elements in tuples shouldn't be allowed to have a trailing comma.
This behavior was likely introduced in #28919, but since that PR doesn't mention rest types, probably it was an oversight.

Playground Link: Playground Link

Related Issues:

babel/babel#10769 - If this is the expected behavior, we'll fix it in Babel. If instead, you think that this should be fixed in TypeScript, let me know because this should first be fixed in prettier to avoid a broken development workflow.

Activity

  1. RyanCavanaugh commented on Dec 3, 2019

    @RyanCavanaugh
    Member

    I think had we known at the time, this would have been disallowed, but I'm not thrilled about taking what is observably a breaking change with no apparent upside. It'd be better if Babel could just support it.

  2. nicolo-ribaudo commented on Dec 3, 2019

    @nicolo-ribaudo
    ContributorAuthor

    Ok 👍

    (Just in case you change your mind, I'll be happy to disallow it again in the next major version of Babel 😛)

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions