ts 联合类型

参考:https://www.jianshu.com/p/655a6471f50f

指多个类型的合并类型

1. 基础类型联合

let a: string | number;
a = 1; //ok 
a= "a"//ok

2. 对象类型联合

对象联合类型只能访问联合中所有共同成员

interface Women{
  age: number,
  sex: string,
  cry(): void
}
interface Man{
  age: number,
  sex: string,
}
declare function People(): Women | Man;
let people = People();
people.age = 18; //ok
people.cry();//error 非共同成员