类型别名
type Plustype = (x: number, y: number) => number;
let sum: Plustype = (x: number, y: number) => {
return x + y;
};
type stringOrNumber = string | number;
let a: stringOrNumber = 123;
let b: stringOrNumber = "abc";
字面量类型
let a: "up" | "down" | "left" | "right"
type Direction = "up" | "down" | "left" | "right"
let b: Direction
交叉类型
interface IName {
name: string;
}
interface IAge {
age: number;
}
type IPerson = IName & IAge; // 这个有点像继承多个接口的意思
let zhangSan: IPerson = {
name: "zhangSan",
age: 18,
};
class Lisi implements IName, IAge {
name: "lisi";
age: 18;
}