简体   繁体   English

多种类型的打字稿联合

[英]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. 全部,我有4个非常相似的打字稿类,并且我可以将这4个类中的任何一个传递给相同的函数。 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

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. 它的行为就像您以扩展形式编写的一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM