Typescript: Drop emit of last semicolon in single-line object literal types

Created on 11 Nov 2019  ·  3Comments  ·  Source: microsoft/TypeScript

Tracking follow-up to #33402

When synthetic object literal type nodes are printed on a single line, they come out like

type X = { a: string; b: string; };

While working on semicolon formatting features, I briefly had the formatter remove the semicolon after b: string;. The result was well-received but I ultimately decided the logic didn’t belong in the formatter; if this was going to be the canonical formatting of single-line object type literals, they should simply come out of the emitter that way.

Suggestion

Most helpful comment

Why semicolons? Why not just

type X = { a: string, b: string };

I only usually use semicolons in interfaces.

All 3 comments

Why semicolons? Why not just

type X = { a: string, b: string };

I only usually use semicolons in interfaces.

This is also how I write single-line object types. Honestly I’m a little worried that _any_ change I make here will incite an angry mob composed of people with a particular lint rule. So I guess the answer to your question is “fear of public ridicule,” or more seriously, a preference not to shake things up for everyone without a good reason. Which is why I’m not totally confident that I will make this change at all.

Personally I'd prefer comma.
Prettier users will get their ; for free*

type X = { a: string, b: string };
// emitted as
type X = { a: string; b: string };

* for better or worse (definitely worse, because it will replace my ,)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weswigham picture weswigham  ·  3Comments

blendsdk picture blendsdk  ·  3Comments

bgrieder picture bgrieder  ·  3Comments

DanielRosenwasser picture DanielRosenwasser  ·  3Comments

wmaurer picture wmaurer  ·  3Comments