【发布时间】:2020-02-07 05:07:54
【问题描述】:
所以我有一个这样的界面:
interface Test {
// ...
created_at: Timestamp;
// ...
}
我从这样的函数返回一个对象:
export const getTest = functions.https.onCall(async (data, context) => {
if (!context.auth) {
return null;
}
let snap = await admin
.firestore()
.collection('test')
.get();
return snap.docs.map(r => ({ // Add id to the output
id: r.id,
...r.data()
})[0];
});
所以我应该在我的应用程序中获取时间戳对象,但这是我在 chrome 控制台中得到的,当我尝试从函数中获取对象时,如下所示:
// Using AngularFireFunctions
let result: Test = await this.fns.httpsCallable<void, Test>('getTest')().toPromise();
这是result.created_at的全部内容:
当我调用result.created_at.toDate() 时,我收到....created_at.toDate is not a function 错误。
我能做些什么来改变这种情况?
这就是我现在所坚持的:
result.created_at = new Date(result.created_at._seconds * 1000);
【问题讨论】:
标签: javascript typescript firebase google-cloud-firestore google-cloud-functions