【问题标题】:I am getting this error: Type '(err: Error) => void' has no properties in common with type 'QueryOptions'.ts(2559) and I don't know what's the cause我收到此错误:类型 '(err: Error) => void' 与类型 'QueryOptions'.ts(2559) 没有共同的属性,我不知道是什么原因
【发布时间】:2021-07-27 03:55:00
【问题描述】:

这是我的“删除用户”路线:

app.post("/deleteuser", async (req, res) => {
 const { id } = req?.body;
 await User.findByIdAndDelete(id, (err: Error) => {
  if (err) throw err;
 });
 res.send("success");
});

【问题讨论】:

  • 请另外贴出真实代码。您的错误消息涵盖了其中的一部分。
  • 我已经编辑过了。谢谢!

标签: node.js typescript error-handling


【解决方案1】:

[已解决]

app.post("/deleteuser", async (req, res) => {
  const { _id } = req?.body;
  try {
    await User.findByIdAndDelete(_id);
    res.send('success');
  } catch (err) {
    res.status(500).json({
    message: err.message
    });
  }
});

【讨论】:

    猜你喜欢
    • 2023-01-11
    • 1970-01-01
    • 2021-01-14
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    相关资源
    最近更新 更多