- 联合类型:多种数据类型之一(或)
- 交叉类型:同时满足多种类型(且)
联合类型
let arr: (number | string)[] = [1,2,'a','b']
// 类型别名
type ID = (number | string)
let id1: ID = 1
let id2: ID = '2'
// 只能是 数字1 或字符串"1"
let n: 1 | "1";
n = 1;
n = "1";
交叉类型
let user: { name: string; age: number } & { sex: string };
user = {
name: "zhangsan",
age: 12,
sex: "男",
};