【发布时间】:2020-02-27 07:27:33
【问题描述】:
我得到错误:
TS2358:“instanceof”表达式的左侧必须是 type 'any',对象类型或类型参数。
编译以下代码时:
const animal: Tiger | Monkey | Goat = fetchAnimal();
if (!animal instanceof Tiger && !animal instanceof Monkey) {
alert('It is safe to touch the animal');
}
【问题讨论】:
标签: typescript compiler-errors union instanceof