Firebase:尝试返回服务器时间戳时出现命名空间错误

u0sqgete  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(129)

不知道我做错了什么。错误指向返回类型。我试图小心添加太多的名称空间,因为我不想减慢函数的冷启动,但显然我错过了一些关键的东西...

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const fs = admin.firestore();

/**
 * Returns the server timestamp from Firestore.
 *
 * @returns {Timestamp} The server timestamp.
 */
export function getServerTimestamp(): firebase.firestore.Timestamp {
  // return firebase.firestore.FieldValue.serverTimestamp();
  return FirebaseFirestore.FieldValue.serverTimestamp();
}
nmpmafwu

nmpmafwu1#

您可以使用admin.firestore.TimestampTimestamp

import {Timestamp} from "firebase-admin/firestore";

要键入函数的返回类型并返回Firestore服务器时间戳,您可以使用以下代码段之一:

import * as admin from "firebase-admin";
admin.initializeApp();
/**
 * Returns the server timestamp from Firestore.
 * @return {Timestamp} The server timestamp.
 */
export function getServerTimestamp(): admin.firestore.Timestamp {
  // return firebase.firestore.FieldValue.serverTimestamp();
  return admin.firestore.Timestamp.now();
}

import * as admin from "firebase-admin";
import {Timestamp} from "firebase-admin/firestore";  
admin.initializeApp();
/**
 * Returns the server timestamp from Firestore.
 * @return {Timestamp} The server timestamp.
 */
export function getServerTimestamp(): Timestamp {
  // return firebase.firestore.FieldValue.serverTimestamp();
  return admin.firestore.Timestamp.now();
}

参考号:Timestamp

相关问题