firebase.firestore.FieldValue.serverTimestamp() doesn't support Timestamp data type

Discussão em 'Angular' iniciado por Sampath, Fevereiro 23, 2025.

  1. Sampath

    Sampath Guest

    async createUser(uid: string, email: string) {
    await this.afs.doc<UserProfileModel>(FirestoreDbConstant.USER_PROFILES + `/${uid}`).set({
    email,
    createdDate: firebase.firestore.FieldValue.serverTimestamp(),
    });
    }


    This model works

    export interface UserProfileModel {
    email: string;
    createdDate?: firebase.firestore.FieldValue;
    }


    But Why I cannot use Timestamp here like so?

    import { Timestamp } from '@firebase/firestore-types';

    export interface UserProfileModel {
    email: string;
    createdDate?: Timestamp;
    }


    Then it gives this error:


    (property) UserProfileModel.createdDate?: Timestamp Type 'FieldValue' is missing the following properties from type 'Timestamp': seconds, nanoseconds, toDate, toMillists(2739) user-profile.model.ts(11, 5): The expected type comes from property 'createdDate' which is declared here on type 'UserProfileModel'
    ​

    The problem here is I need to use toDate() on the template. But it doesn't work with the createdDate?: firebase.firestore.FieldValue;

    <p>{{invitedEvent.startDatetime.toDate() | amDateFormat: 'MMM DD'}}</p>

    Continue reading...

Compartilhe esta Página