Tommie Jones
Tommie Jones

Reputation: 1011

typescript union of multiple types

All, I have 4 typescript classes that are very similar and I can pass any of the 4 classes to the same function. So my function signature looks like this.

foo(a:Plane |Rocket | Bird | Balloon) { dostuff;}

Is it possible to create a class or interface that is a union of all four

something like

class Flyer = Plane | Rocket | Bird | Balloon

Upvotes: 1

Views: 681

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221332

You can create a type alias:

type Flyer = Plane | Rocket | Bird | Balloon;

This is only an alias; it will behave identically as if you had written it in its expanded form.

Upvotes: 6

Related Questions