Reputation: 763
I was using firebase 7.16.1 and I was importing and declaring a property as Timestamp this way:
import { firestore } from 'firebase/app';
export class CourseEventMessage {
sentTimestamp: firestore.Timestamp;
}
But after upgrading to firebase 8.1.2, the import is getting an error:
Module '"../../../node_modules/firebase"' has no exported member 'firestore'. Did you mean to use 'import firestore from "../../../node_modules/firebase"' instead?ts(2614)
I've tried the following imports, all of them imports ok, but no Timestamp exists on the import.
import firestore from "../../../node_modules/firebase";
import firestore from 'firebase';
import firestore from 'firebase/app';
The only way I could found that imports Timestamp was:
import * as firebase from 'firebase/app';
export class CourseEventMessage {
sentTimestamp: firebase.default.firestore.Timestamp;
}
So what's the proper way to import the Timestamp class?
Upvotes: 2
Views: 1558
Reputation: 65
It took me ages to find the right solution for v9, hope it helps someone. You don't need the whole "firebase.firestore.FieldValue...", what works is actually much easier:
import { updateDoc, serverTimestamp } from "firebase/firestore";
const updateTimestamp = await updateDoc(docRef, {
timestamp: serverTimestamp()
});
Upvotes: 0
Reputation: 317322
In v8, all of the types for all Firebase products should come from "firebase/app". It's typical to start an import like this, as you see in the documentation for module bundlers:
import firebase from "firebase/app"
Do NOT use the old form from v7:
import * as firebase from "firebase/app" // this no longer works the way you expect
Timestamp can be found in firebase.firestore.Timestamp
.
import firebase from 'firebase/app';
export class CourseEventMessage {
sentTimestamp: firebase.firestore.Timestamp;
}
If you want to abbreviate that a bit, use a type alias:
type Timestamp = firebase.firestore.Timestamp;
export class CourseEventMessage {
sentTimestamp: Timestamp;
}
Upvotes: 8