question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TypeScript] Trailing commas from type exports removed

See original GitHub issue

Prettier 1.16.4 Playground link

--parser typescript
--trailing-comma all

Input:

export type TupleType = [
  number, // exitcode
]

Output:

export type TupleType = [
  number // exitcode
];

Expected behavior: Keep input as-is

Note that using babel, babel-flow or flow parser keeps the trailing comma

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rista404commented, Aug 1, 2019

@Eksapsy I’m not sure, it just somehow stopped adding commas without me changing configuration or versions. For what it’s worth, I’m using eslint, and I can share my .eslintrc file 😃

0reactions
exapsycommented, Aug 2, 2019

Oh thank you very much @rista404 . I use tslint though and I find it hard to believe that it would fix the problem itself 😛 I very much appreciate the effort though! 😄

I short of “fixed” it by just using an interface instead of having a type declaration right away. Like this:

Before

const [contextMenuOrigin, setContextMenuOrigin] = useState<{
    left: number
    top: number
  }>({ left: 0, top: 0 })

After

interface IOrigin {
    left: number,
    top: number,
}
const [contextMenuOrigin, setContextMenuOrigin] = useState<IOrigin>({ left: 0, top: 0 })

The problem is potentially that prettier thinks that type declaration inside a generic shouldn’t have commas at all. So, it’s not “fully compatible” with Typescript in some way probably, but I wont jump to conclusions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Allow Trailing Commas (Comma-Dangle) With ...
Allowing comma-dangle in TypeScript requires two configurations in your ESLint setup. At first, you must turn off ESLint's default comma-dangle ...
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
Trailing commas should not be used
Trailing commas should not be used ... Most browsers parse and discard a meaningless, trailing comma. Unfortunately, that's not the case for Internet...
Read more >
Add formatting options to insert/remove trailing commas in ...
Add formatting options to insert/remove trailing commas in Object Literals, Function Declaration Parameters, Function Call Arguments, ES6 Imports/Exports.
Read more >
Single type parameter T should have a trailing comma. ...
You don't need the trailing comma if you're not writing TSX (TypeScript + JSX). You do need it if you are. And if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found