Firebase - Using Firestore's FieldValue

Viewed 717

In a model, I have the following. However, upon upgrading to Version 9 of firebase, this no longer works.

'"/node_modules/firebase/compat/index"' has no exported member 'firestore'.

import firebase from 'firebase/app';
import 'firebase/firestore';

export interface ModelTest {
    date: firebase.firestore.FieldValue | firebase.firestore.Timestamp | Date;
}

I've had a quick browse through the documentation and haven't found a solution for this (yet..). Firebase has a 'compat' mode which is apparently temporary. To avoid implementing something temporary, is there a new way to import?

====

UPDATE

This seems to work:

import { Timestamp, FieldValue } from "firebase/firestore";

export interface ModelTest {
  date?: FieldValue | Timestamp | Date;
}
1 Answers

You should import the compat version of Firestore or any Firebase service that you are using as well if the core is imported from compat:

import firebase from 'firebase/compat/app';
import 'firebase/compat/firestore';
// import 'firebase/compat/[SERVICE_NAME]';
// compat version    ^^^

You can explicitly import FieldValue from non-compat version but it'll be best to use a single version for consistency.

Related