type 继承
type TypeA = {
name: string;
};
type TypeB = {
age: number;
country: string;
};
type TypeC = TypeA & TypeB;
const example: TypeC = {
name: 'Tom',
age: 30,
country: 'Chile',
};
interface 继承
type TypeA = {
name: string;
age: number;
};
interface InterfaceA {
country: string;
}
type TypeB = TypeA & InterfaceA;
const example: TypeB = {
name: 'Tom',
age: 30,
country: 'Chile',
};
interface extends 继承
type TypeA = {
name: string;
country: string;
};
interface InterfaceA extends TypeA {
age: number;
}
const example: InterfaceA = {
name: 'Tom',
age: 30,
country: 'Chile',
};
interface extends 继承多个
type TypeA = {
name: string;
};
type TypeB = {
country: string;
};
interface InterfaceA extends TypeA, TypeB {
age: number;
}
const example: InterfaceA = {
name: 'Tom',
age: 30,
country: 'Chile',
};
参考