typescript里 泛型中 & 是什么意思 ?

Intersection Types An intersection type combines multiple types into one. This allows you to add together existing types to get a single type that has all the features you need. For example, > Person & Serializable & Loggable is a > Person and > Serializable and > Loggable. That means an object of this type will have all members of all three types. 表示这个变量同时拥有所有类型所需要的成员,可以作为其中任何一个类型使用。

interface中的extends

  1. // 生物体的接口
  2. interface Creature {
  3. name: string;
  4. }
  5. // 动物接口 继承生物接口
  6. interface Animal extends Creature {
  7. // 自己拥有的属性 action
  8. action(): void;
  9. }

一个接口可以继承多个接口

  1. // 生物体的接口
  2. interface Creature {
  3. name: string;
  4. }
  5. // 动物接口
  6. interface Animal {
  7. // 自己拥有的属性 action
  8. action(): void;
  9. }
  10. // 狗Dog接口继承 生物Creature 和 Animal 多继承
  11. interface Dog extends Creature, Animal{
  12. color: string;
  13. }