What’s the purpose of a leading pipe when declaring a type on Typescript

It’s purely stylistic, there is no functional difference.

Consider the following:

type Foo = Bar
  | Baz
  | Bap

compared to this:

type Foo =
  | Bar
  | Baz
  | Bap

The second example is a lot cleaner, and it’s immediately clear that the three things on the right side of the |s are the constituents of the union.

Clearly, you wouldn’t add a leading | when defining everything on one line:

type T = A | B

Leave a Comment