【TS】type和interface的区别
type能为基本类型起别名
type aliaName = string;
type能实现联合类型
interface Dog{
wang();
}
interface Cat{
miao();
}
type Pet = Dog | Cat;
type实现元组类型
type PetList = [Dog, Cat];
interface可以进行合并
interface Animal{
name: string;
age: number;
}
interface Animal{
sayHi: () => void;
}
// 最后的Animal接口为二者的结合
interface Animal{
name: string;
age: number;
sayHi: () => void;
}