You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{collection,getFirestore,onSnapshot}from"firebase/firestore";functionmain(){constfirestore=getFirestore();constcolRef="col";onSnapshot(collection(firestore,colRef),(snap)=>{if(snap.empty){return;}constdocuments=snap.docs.map((doc)=>({id: doc.id,
...doc.data(),// error: Spread types may only be created from object types}));},(error)=>{console.warn(error);});}
In this code snap is QuerySnapshot<unknown> which makes it hard to use .data(). This can be fixed by either:
Casting doc.data() as any
Using onSnapshot<any>
Is this the intended behavior in the new SDK?
The text was updated successfully, but these errors were encountered:
TypeScript does not retain the type of the generic class unless the type is part of the API surface. Unfortunately, CollectionReference<T> does not refer to T in any of its members. This means that we have to change the API to accommodate this. I will prepare a PR, but we need to obtain approval for this API change internally.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
Relevant Code:
index.ts
In this code
snap
isQuerySnapshot<unknown>
which makes it hard to use.data()
. This can be fixed by either:doc.data() as any
onSnapshot<any>
Is this the intended behavior in the new SDK?
The text was updated successfully, but these errors were encountered: