极客时间返利平台,你可以在上边通过山月的链接购买课程,并添加我的微信 (shanyue94) 领取返现。
山月训练营之面试直通车 服务上线了,从准备简历、八股文准备、项目经历准备、面试、面经、面经解答、主观问题答复、谈薪再到入职的一条龙服务。

# typescript 中 interface 与 type 有何区别

Issue

欢迎在 Gtihub Issue 中回答此问题: Issue 730 (opens new window)

https://stackoverflow.com/questions/37233735/interfaces-vs-types-in-typescript

interface 是接口,type 是类型,本身就是两个概念。只是碰巧表现上比较相似。 希望定义一个变量类型,就用 type,如果希望是能够继承并约束的,就用 interface。 如果你不知道该用哪个,说明你只是想定义一个类型而非接口,所以应该用 type。

Author

回答者: coderhn (opens new window)

interface 和 type 都可以用来声明和约束变量类型结构,interface 可以被继承重载,type 要想被继承只能使用联合&,而且 interface 的性能比 type 更好

Last Updated: 2/13/2023, 10:50:25 AM