Which Data Type does Firestore use for it's Timestamps?

Viewed 2311

I'm sure anyone who already knows will think this is an obvious question but I've already spent a lot of time searching the docs for this.

I would think you do something like this, but this doesn't work:

import * as firebase from 'firebase/app';

export interface ChatMessage {
  message: string;
  dateSent: firebase.firestore.serverTimestamp();
}

Also, I've seen this in some places, but it doesn't work for me either...

firebase.firestore.FieldValue.serverTimestamp();

I just get Namespace 'firebase.firestore' has no exported member 'FieldValue'.

2 Answers

Figured out what I was doing wrong! It should be this...

import * as firebase from 'firebase/app';

export interface ChatMessage {
  message: string;
  dateSent: firebase.firestore.FieldValue;
}

OR

import { firestore } from 'firebase/app';

export interface ChatMessage {
  message: string;
  dateSent: firestore.FieldValue;
}

Then when I go to make a chat message, it will let me do this:

<ChatRoom>{
  newCount: newTotal,
  lastMessageDate: firebase.firestore.FieldValue.serverTimestamp();
});

I think you need to change your import statement to the following:

import * as firebase from 'firebase';
Related