Closed
Description
[REQUIRED] Describe your environment
- Operating System version: macOS
- Browser version: Chrome latest
- Firebase SDK version: 9.0.0-beta.1
- Firebase Product: firestore
[REQUIRED] Describe the problem
Steps to reproduce:
Relevant Code:
index.ts
import { collection, getFirestore, onSnapshot } from "firebase/firestore";
function main() {
const firestore = getFirestore();
const colRef = "col";
onSnapshot(
collection(firestore, colRef),
(snap) => {
if (snap.empty) {
return;
}
const documents = 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?