instanceof 类型保护问题

来源:4-7 编写基础请求代码 - demo 编写

Mesry

2020-12-04

The right side of the instanceof needs to be a constructor function, and TypeScript will narrow down to:

the type of the function’s prototype property if its type is not any
the union of types returned by that type’s construct signatures

请问老师,在用instanceof类型保护时,上面两句话是什么意思,官网给出的,没有看懂

写回答

1回答

ustbhuangyi

2020-12-04

instanceof类型保护是使用类型的构造函数缩小类型的一种方法,你可以简单地理解 instanceof 的右侧需要是一个构造函数。


0
3
Mesry
回复
ustbhuangyi
好的,那在问您下,我们默认写一个class类 class Animal { constructor(){} test(){} } typescript默认解析这个类的原型属性是对象类型{constructor(){},test(){}} 是嘛
2020-12-06
共3条回复

下一代前端开发语言 TypeScript从零重构axios

课程从零开始重构功能完整的JS库,是学习造轮子的不二之选!

2629 学习 · 877 问题

查看课程