// 1,写法不一样
type MyType = {
name: string
age: number
}
interface MyType {
name: string;
age: number
}
// 2,拓展方式不一样
type MyType = {
name: string
age: number
}
type MyType2 = MyType & {
last: string
}
interface MyType {
name: string;
age: number
}
interface MyType2 extends MyType {
last: string
}
// 3,interface可以重复定义拓展属性,type不行
interface MyType {
name: string
}
interface MyType {
age: number
}
/*
等同于 interface MyType {
name: string;
age: number
}
*/
type MyType = {
name: string
}
type MyType = { // 报错
age: number
}
标签:typescript,string,number,MyType,interface,type,name From: https://www.cnblogs.com/itpyy/p/17146510.html