【发布时间】:2023-01-11 04:47:23
【问题描述】:
我在 Node 控制器中有以下路由,它给我一个阻止 Node 运行的错误
public async deletePost(req: Request, res: Response) {
const { id } = req.params;
const deletedPost = await BlogPostModel.findByIdAndDelete(id, err => {
if (err) {
res.status(400).send.send('Error deleting post');
}
});
// needs to send error if post not found (400 status code)
res.status(200).send(deletedPost);
}
我的代码的 err => { 部分出现错误:
Type '(err: any) => void' has no properties in common with type 'QueryOptions'
我不完全理解这个错误,但听起来它要求我在错误处理回调函数中输入参数。但是,我也试过(err:any)=>,但效果不佳。谁能在这里告诉我如何正确使用回调函数进行错误处理?
【问题讨论】:
标签: node.js typescript express mongoose