1

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
2

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.