- interface 和 type 都可以用来描述 object 或者 function 的类型 ```typescript interface Person { name: string age: number }
interface SetPerson { (k: string, v: string): void }
type Person = { name: string age: number }
type SetPerson = (k: string, v: string) => void
2. 区别于interface ,type可用于其他类型, 例如 primitives unions 和 tuples
```typescript
// primitive[原始数据类型]
// boolean string number bigint symbol undifined numm void 枚举类型 字面量类型
type name = string
// object
type AgeX = {x: number}
type AgeY = {y: number}
// union
type Age = AgeX | AgeY
// tuple
type Age = [number, string]
- 两者都可以扩展,且相互不排斥 ```typescript // 同类型扩展 interface PartialPointX { x: number }
interface Point extends PartialPointX { y: number }
// 相当于 // interface Point { // x: number // y: number // }
type PartialPointX = { x: number } type Point = PartialPointX & { y: Number }
// 相当于 // type Point = { // x: number // y: number //}
// 互相扩展 type -> interface type PartialPointX = { x: number } interface Point extends PartialPointX { y: number }
// 互相扩展 interface -> type interface PartialPointX { x: number } type Point = PartialPointX & { y: Number }
```