Skip to content

Typescript: trailing comma in interface is not allowed #1858

Closed
renovatebot/renovate
#231

Description

@dotlouis

Hi, I just ran prettier on my code base and had only a single issue which comes from an interface.

Demo

generated TS:

export interface ShopQueryResult {
  chic: boolean;
  location: number[];
  menus: Menu[];
  openingDays: number[];
  closingDays: [
    {
      from: string,
      to: string,
    }, // <== this one
  ];
  shop: string;
  distance: number;
}

It basically comes down to the trailing comma inside the closingDays array, after the object literal.
Typescript compiler is not happy with it. Don't know why. My guess is that it should be accepted like any other trailing commas but it's probably easier to fix prettier than typescript.

Thanks a lot for this awesome tool, I look forward to use it a lot more,
Cheers

Activity

  1. added
    lang:typescript
    on Jun 2, 2017
  2. self-assigned this
    on Jun 2, 2017
  3. added a commit that references this issue on Jun 2, 2017
    adb125f
  4. added a commit that references this issue on Jun 2, 2017
    9ed94c7
  5. vjeux commented on Jun 2, 2017

    @vjeux
    Contributor

    cc @DanielRosenwasser, another place where typescript doesn't support trailing commas

  6. DanielRosenwasser commented on Jun 2, 2017

    @DanielRosenwasser

    The problem is not the interface, the problem is that tuple types are not allowed to have trailing commas.

    Something to keep in mind: did you actually mean to write a tuple type, or did you mean to write {from: string, to: string}[] or Array<{from: string, to: string}>?

  7. dotlouis commented on Jun 2, 2017

    @dotlouis
    Author

    You are absolutely right, that's what I meant !
    Thanks for the prompt answer !

  8. vjeux commented on Jun 2, 2017

    @vjeux
    Contributor

    I just published 1.4.1 which fixes it!

  9. DanielRosenwasser commented on Jun 2, 2017

    @DanielRosenwasser

    Great! For the record, this is probably a good argument against trailing commas in tuple types - while I think it makes sense for object literals and argument lists, I find it more questionable in this context. 😃

  10. added
    locked-due-to-inactivity
    on Jul 7, 2018
  11. locked as resolved and limited conversation to collaborators on Jul 7, 2018
  12. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

lang:typescriptlocked-due-to-inactivity

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions