interface 描述对象或类的形状,支持声明合并(同名 interface 自动合并)与 extends 继承;type 是类型别名,能表达任意类型——联合、交叉、元组、映射类型、条件类型。对象形状上两者大多可互换;需要联合类型、工具类型组合时只能用 type;定义公开 API 的对象类型、需要被 implements 或预留扩展时用 interface。

细节差异:声明合并既是特性(扩展第三方库类型、给 Window 打补丁)也是隐患(意外合并);type 同名直接报错。性能上 interface 的继承检查比 type 的交叉类型更高效,报错信息也更友好。易错点:implements 也接受对象形状的 type 别名,但不能是联合类型;type 可以做 interface 做不到的 typeof、keyof 组合。追问:声明合并的实际场景、交叉类型与 extends 的差异。

interface User { name: string }
type Status = 'active' | 'disabled' // interface 做不到
type WithId = User & { id: number }