geofirex
geofirex copied to clipboard
Doc Update: How to declare firestore in nodejs Typescript?
The readme says:
With Typescript:
import * as geofirex from 'geofirex'; const geo = geofirex.init(firebase);
But where is firebase coming from? I have:
import * as admin from 'firebase-admin';
import * as geofirex from 'geofirex';
const app = admin.initializeApp();
//const geo = geofirex.init(app); // causing error, see below
When I do:
const geo = geofirex.init(app);
I get:
Argument of type 'App' is not assignable to parameter of type 'typeof firebase'. Type 'App' is missing the following properties from type 'typeof firebase': registerVersion, setLogLevel, onLog, app, and 6 more.ts(2345)
How do I init geofirex in typescript for nodejs?
your app is not initialized correctly. you need to provide a firebase config object
@muc1 The config is optional. See here: https://firebase.google.com/docs/admin/setup#initialize-without-parameters
Nevertheless, however I initialise the app, with or without config, the problem I have is that I don't know how to initialise the geofirex.
@Kayes-Islam Yeah, is nothing related to the config, faced this same issue a couple of days ago deploying functions to firebase. The way I resolved it and works without problem is doing the require-way as is in the readme for the admin-sdk, like this in typescript:
import * as admin from 'firebase-admin';
import {GeoFireClient} from "geofirex";
admin.initializeApp();
const geo: GeoFireClient = require('geofirex').init(admin);
Hope it helps! 👌
Thanks @BrDrawolf, your answer has solved this issue for me.
I still think it's an issue/improvement if we could use the typescript import without having to require(). I'll leave the issue open for this.