【发布时间】:2020-09-06 10:22:40
【问题描述】:
我正在尝试使用 toDate() 在 TypeScript 中将 timestamp 对象从 Firestore 转换为 Date 对象。
import { AngularFirestore } from '@angular/fire/firestore';
...
constructor(private database?: AngularFirestore) {...}
...
const someVariable = a.date.toDate();
虽然该功能在开发模式下运行良好,但我收到 TypeScript 编译检查错误。此外,由于此错误,我无法构建 prod 版本(使用 ng prod)。
a.date.toDate() ~~~~ src/app/project/some.service.ts:74:36 -
错误 TS2339:“日期”类型上不存在属性“toDate”。
有什么建议可以解决这个问题吗?
【问题讨论】:
-
这里 a.date 是
{seconds: <sec>, nanoseconds: <nanosec>}形式的 Firestore 时间戳。根据文档转换时间戳对象,我们需要调用toDate()方法,这就是我正在做的...... -
"...在开发模式下工作正常..." 你不是在“开发模式”下使用 TypeScript 吗?在开发中使用它是它的基本目的。
标签: angular typescript timestamp angularfire