Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q706】typescript 中 interface 与 type 有何区别 #730

Open
shfshanyue opened this issue Oct 3, 2021 · 3 comments
Open

【Q706】typescript 中 interface 与 type 有何区别 #730

shfshanyue opened this issue Oct 3, 2021 · 3 comments
Labels

Comments

@shfshanyue
Copy link
Owner

No description provided.

@shfshanyue shfshanyue added the ts label Oct 3, 2021
@shfshanyue
Copy link
Owner Author

@illumi520
Copy link

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

@coderhn
Copy link

coderhn commented Nov 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants