0

I'm using the Firebase Admin SDK in my Express + Typescript server. I'm trying to use Firestore's method withConverter() However, I get the error "Cannot find namespace 'FirebaseFirestore'.ts(2503)". How can I deal with this?

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});

const firestore = admin.firestore();

interface BlogpostColletion {
    text: String,
    title: String,
}

interface UsersCollection {
    blogposts: BlogpostColletion
}

const converter = {
    toFirestore: (data: UsersCollection) => data,
    // PROBLEM HERE "Cannot find namespace 'FirebaseFirestore'.ts(2503)" 
    fromFirestore: (snap: FirebaseFirestore.QueryDocumentSnapshot) =>
        snap.data() as UsersCollection
}
A.G
  • 13
  • 4
  • Have you tried `admin.firestore.QueryDocumentSnapshot` instead of `FirebaseFirestore.QueryDocumentSnapshot`? – Dharmaraj Sep 25 '21 at 15:58
  • 1
    Thank you. Changing to "admin.firestore.QueryDocumentSnapshot" gave the issue "cannot find namespace admin". But changing the import of admin from "var admin = require("firebase-admin")" to "import * as admin from 'firebase-admin'" seems to have solved it :) – A.G Sep 28 '21 at 07:02

1 Answers1

0

You can import QueryDocumentSnapshot from Admin SDK like this:

import * as admin from "firebase-admin"

fromFirestore: (snap: admin.firestore.QueryDocumentSnapshot) 
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84