Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'.

like image 580
Jus10 Avatar asked Nov 16 '17 22:11

Jus10


1 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();
});
like image 185
Jus10 Avatar answered Oct 09 '22 09:10

Jus10