lmcq / firebase-firestorm

Firebase Firestorm is an ORM for Firestore which can be used with Typescript.
MIT License
252 stars 19 forks source link

fix(admin-firestore): add types from @google-cloud/firestore #4

Open mkorenko opened 4 years ago

mkorenko commented 4 years ago

When initializing an app using firebase-admin with admin.firestore() instead of firebase.firestore():

import * as functions from 'firebase-functions';
admin.initializeApp(functions.config().firebase);
const firestore = admin.firestore();
firestorm.initialize(firestore);

getting:

  1. ts error error TS2345: Argument of type 'FirebaseFirestore.Firestore' is not assignable to parameter of type 'firebase.firestore.Firestore'.
  2. after fixing it, getting runtime error for @timestamp() and @geopoint() fields : TypeError: Cannot read property 'Timestamp' of undefined

I guess that happens because different types are imported by non-admin and admin SDKs: from firebase/index.d.ts and @google-cloud/firestore/types/firestore.d.ts respectively.

Fixed that for TimeStamps and GeoPoints using combined types/fallback refs, and also types in firestorm.initialize()

Legogris commented 4 years ago

Fails in CI:

src/firestore.ts
ES2015 module syntax is preferred over custom TypeScript modules and namespaces. (@typescript-eslint/no-namespace)

export namespace firestore {
Mistic92 commented 4 years ago

Any update?:)