Skip to content

TypeScript 中 interface 和 type 有什么区别?

  • interface 和 type 都可以用来定义对象类型,但 interface 创建的对象类型只能是类创建的对象,而 type 创建的对象类型可以是类创建的对象,也可以是函数创建的对象。
  • interface 可以继承,type 不能继承。
  • interface 可以重复定义,type 不能重复定义。
  • interface 可以定义属性,type 不能定义属性。
  • interface 可以定义方法,type 不能定义方法。

MIT Licensed | Keep Learning.