node.js - 快速打字稿中的猫鼬$gt运算符?
问题描述
我需要找到令牌尚未过期的用户。
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'.
打字稿评估$gt: Date.now()
为类型注释。我正在将我的 node.js 项目转换为 typescript,这是我唯一想不通的事情。
解决方案
Date.now()
从纪元返回一个整数,UTC 毫秒。用于new Date()
获取Date
对象(内部仍然是 UTC)。
推荐阅读
- angular - 角度引导日期选择器不调用函数
- javascript - Laravel 6 带删除的多文件预览
- android-studio - android studio更新补丁在哪里下载的?
- python - 从文件 md5 和文件名中生成一致的 uuid,如哈希
- reactjs - 将 UI 组件双向绑定到可观察对象以减少渲染的最佳方法是什么?
- flutter - Flutter:如何将容器的高度调整为其连续兄弟的最大高度
- python - python中的'if'和'if not',循环搜索文本文件中的特定子字符串。两者有什么区别?什么时候用哪个?
- types - 我如何让 Agda 的宇宙检查器相信我所做的事情是有根据的?
- javascript - Enter 键的行为类似于 JavaScript 中的箭头键
- amazon-web-services - 将 Elasticache 与 RDS 连接起来?