不支持的字段值:函数(在字段 creationTime 中找到)

Unsupported field value: a function (found in field creationTime)

用户-profile.ts

export interface UserProfile {
    id: string;
    name: string;
    email: string;
    phone?: string;
    creationTime?: any;
}

service.ts

async signUp(name: string, email: string, password: string): Promise<void> {
    try {
      const user: firebase.auth.UserCredential = await this.afAuth.auth.createUserWithEmailAndPassword(email, password);
      const userProfileDocument: AngularFirestoreDocument<UserProfile> = this.fireStore.doc(`userProfiles/${user.user.uid}`);
      const userProfile: UserProfile = {
        id: user.user.uid,
        email: email,
        creationTime: firebase.firestore.Timestamp,
        name: name
      };
      await userProfileDocument.set(userProfile);
    } catch (error) {
    }
  }

控制台出现一个错误:

[2019-02-28T08:01:58.804Z] @firebase/firestore: Firestore (5.8.3):
The timestampsInSnapshots setting now defaults to true and you no
longer need to explicitly set it. In a future release, the setting
will be removed entirely and so it is recommended that you remove it
from your firestore.settings() call now.

这是下一个错误:

FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: a function (found in field creationTime) at new FirestoreError (http://localhost:8100/vendor.js:77381:28) at ParseContext.push../node_modules/@firebase/firestore/dist/index.cjs.js.ParseContext.createError (http://localhost:8100/vendor.js:96125:16) at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseScalarValue (http://localhost:8100/vendor.js:96467:27) at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (http://localhost:8100/vendor.js:96338:29) at http://localhost:8100/vendor.js:96354:41 at forEach (http://localhost:8100/vendor.js:77483:13) at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseObject (http://localhost:8100/vendor.js:96353:13) at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (http://localhost:8100/vendor.js:96312:25) at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseSetData (http://localhost:8100/vendor.js:96177:31) at DocumentReference.push../node_modules/@firebase/firestore/dist/index.cjs.js.DocumentReference.set (http://localhost:8100/vendor.js:97049:45)

您需要进行如下操作:

第一个错误: https://github.com/angular/angularfire2/issues/1993#issuecomment-456481677

第二个错误:

  const userProfile: UserProfile = {
    id: user.user.uid,
    email: email,
    creationTime: firebase.firestore.FieldValue.serverTimestamp(),
    name: name
  };

如文档中所述,firebase.firestore.FieldValue.serverTimestamp() 将 return 一个 "sentinel" 对象,您在构建要写入 Firestore 的对象时使用该对象。它将向服务器指示它应该用实际时间戳替换它。