Skip to content

A binding pattern without rest element can have a trailing comma #24628

Description

@ikatyang

TypeScript Version: 2.9.1/3.0.0-dev.20180602

Search Terms:

  • trailing comma
  • binding pattern
  • A rest parameter or binding pattern may not have a trailing comma.

Code

declare const anything: any[];

let a;

[
  a,
] = anything;

let [
  b,
] = anything;

Expected behavior:
no error

Actual behavior:

test.ts:6:4 - error TS1013: A rest parameter or binding pattern may not have a trailing comma.

6   a,
     ~

Per ECMAScript Spec, the trailing comma is allowed in a binding pattern without rest element.

image

Playground Link:
link

Related Issues:

(from prettier/prettier#4624)

Activity

  1. mhegazy commented on Jun 4, 2018

    @mhegazy
    Contributor

    PRs welcomed.

  2. mhegazy commented on Jun 4, 2018

    @mhegazy
    Contributor

    thanks @alexandrLamdan1995

  3. bakkot commented on Jun 4, 2018

    @bakkot
    Contributor

    Mohamed Hegazy (@mhegazy) I'm still seeing this on master:

    $ cat in.ts
    let a; [a,] = <any>[];
    
    $ git rev-parse --short HEAD
    7eaa78846e
    
    $ gulp local
    [...]
    
    $ node built/local/tsc.js in.ts
    in.ts:1:10 - error TS1013: A rest parameter or binding pattern may not have a trailing comma.
    
    1 let a; [a,] = <any>[];
               ~
    

    Looks like this was introduced in #22262. I'll submit a PR in a moment here.

  4. tarhunakau commented on Jun 5, 2018

    @tarhunakau

    Will anyone try to fix it? Windows update - crash + BSOD, skype update - crash, Typescript update - crash. Do you have testers for your own products? The worst QA in all over the world... And that is Microsoft.

  5. j-f1 commented on Jun 5, 2018

    @j-f1

    It’ll be fixed by #24672 @BLRplex.

  6. tarhunakau commented on Jun 5, 2018

    @tarhunakau

    Jed Fox (@j-f1) Hope it will not reopened again in few days. Thanks

  7. vaskevich commented on Jun 8, 2018

    @vaskevich

    Can this fix make it into into an earlier release, e.g., 2.9.2? We use Prettier and either we have to rip out all trailing commas or upset the TS compiler to update to 2.9.

  8. vaskevich commented on Jun 8, 2018

    @vaskevich

    As a workaround for anyone who stumbles into this issue, you can just append // prettier-ignore to an offending line and Prettier will not add a trailing comma there to satisfy TS.

  9. 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

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions