Is it possible to import FieldValue from firebase-admin npm using this style?
import { FieldValue } from 'firebase-admin/firestore';
By default my visual studio Code imports in this way:
import {FieldValue} from '@google-cloud/firestore';
but in this way, I have to add a new package only to import FieldValue ...
Is there any way to import it from firebase-admin using Typescript?
In the project directory, run firebase init functions and select TypeScript when prompted for a language for writing functions. When prompted whether to overwrite the existing package.json file, select No unless you are sure you don't want to keep the existing file.
From what I've read, Firebase can use the "Definitely Typed" library to serve type definitions through "@types/firebase". However, if you're using npm to load Firebase (such as with a Webpack-based build process), you can use the type definitions that ship directly with the Firebase module.
The Firebase module doesn't export interfaces - it exports a single object that can be imported using the import-require syntax in TypeScript. Using this single object, you can then access the type definitions using a series of namespaces.
As you can see, each of my variables is being declared with a type definition that is provided by the firebase module. The namespacing makes the declarations fairly verbose, which is why it might be wise to wrap your Firebase implementation in a Gateway / Repository class that can provide easier type inference.
If you import like this:
import { firestore } from 'firebase-admin'
You can find it like this:
firestore.FieldValue
as it's re-exported from @google-cloud/firstore as part of its exported admin.firestore
namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With