【发布时间】:2020-01-20 08:34:26
【问题描述】:
if (!challengeType) {
const { brawl, fight }: any = await userModel
.findOneAndUpdate(
{ _id: req.userData._id },
{ $inc: { 'fight.remaining': -1 } },
{ 'new': true }
)
} else {
const { brawl, fight }: any = await userModel
.findOneAndUpdate(
{ _id: req.userData._id },
{ $inc: { 'brawl.remaining': -1 } },
{ 'new': true }
)
}
// typescript error here
// "Cannot find name brawl", and "Cannot find name fight"
console.log(brawl, fight)
不知道为什么打字稿找不到名字 brawl and fight, 这可能是打字稿错误处理的问题 在 if else 语句的情况下,
但如果脚本正在运行,则没有发生任何问题。
【问题讨论】:
-
我看到的一个问题是您将
const { brawl, fight }: any输入为any。这就是打字稿不会给出编译时错误的原因。如果将类型更改为const { brawl, fight }: userModel之类的类型,如果这些属性不存在,则会引发编译错误
标签: node.js typescript