geofirex icon indicating copy to clipboard operation
geofirex copied to clipboard

Doc Update: How to declare firestore in nodejs Typescript?

Open Kayes-Islam opened this issue 4 years ago • 4 comments

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?

Kayes-Islam avatar May 25 '20 14:05 Kayes-Islam

your app is not initialized correctly. you need to provide a firebase config object

skibaalex avatar May 26 '20 02:05 skibaalex

@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 avatar May 26 '20 07:05 Kayes-Islam

@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! 👌

BrDrawolf avatar May 31 '20 23:05 BrDrawolf

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.

Kayes-Islam avatar Jun 05 '20 02:06 Kayes-Islam