【发布时间】:2021-10-17 06:05:25
【问题描述】:
我需要找到令牌尚未过期的用户。
try {
const user = await User.findOne({
resetToken: passwordToken,
resetTokenExpiration: { $gt: Date.now() },
_id: userId,
});
if (!user) {
throw new NotFoundError();
}
在纯 javascript 中它没有问题。在打字稿中我收到此错误:
Type 'number' is not assignable to type 'Date | undefined'.
typescript 将 $gt: Date.now() 评估为类型注释。我正在将我的 node.js 项目转换为 typescript,这是我唯一想不通的事情。
【问题讨论】:
标签: node.js typescript mongodb express mongoose