老师您好,interface的类型怎么比较?
来源:3-17 【讨论题】什么是 React?

慕村5307545
2021-07-06
我这么写,提示错误,那么怎么写才是正确的比较法
写回答
1回答
-
阿莱克斯刘
2021-07-08
是的,instanceof 对 class有效,对interface不起作用。
原因是instanceof 需要作用于 JavaScript 对象,而interface在便已完成以后不会有任何JavaScript的代码输出,所以instanceof无法在interface中起作用。
stack overflow上有类似的问题:
https://stackoverflow.com/questions/46703364/why-does-instanceof-in-typescript-give-me-the-error-foo-only-refers-to-a-ty/46703380#46703380
012021-07-13
相似问题