I noticed there are no docs for angular-firestore2, only a set of tutorials
Batch writes are covered so I'm partly using the Javascript docs from Firebase
export class FinancialService {
private transCollection: AngularFirestoreCollection<Transaction>;
batch_update_trans(trans) {
let writer = this.afs.firestore.batch();
this.transCollection = this.afs.collection<Transaction>('balance_sheets/'+this.balance_sheet_id+"/transactions/");
for (let t of trans) {
writer.update(this.transCollection.doc(
t.id),t);
}
return writer.commit();
}
}
This doesn't compile with this error:
error TS2345: Argument of type 'AngularFirestoreDocument<{}>' is not assignable to parameter of type 'DocumentReference'.
Type 'AngularFirestoreDocument<{}>' is missing the following properties from type 'DocumentReference': id, firestore, parent, path, and 2 more.
If I cast the AngularFirestoreDocument to <any>
writer.update(<any> this.transCollection.doc(
t.id),t);
it compiles but is causes a runtime error:
ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function WriteBatch.update() requires its first argument to be a DocumentReference, but it was: an object
If I try to cast the AngularFirestoreDocument to DocumentReference:
writer.update(<DocumentReference> this.transCollection.doc(
t.id),t);
It does compile because the types don't overlap each other:
Conversion of type 'AngularFirestoreDocument<{}>' to type 'DocumentReference' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'AngularFirestoreDocument<{}>' is missing the following properties from type 'DocumentReference': id, firestore, parent, path, and 2 more.
If I try to cast AngularFirestoreDocument to <unknown>
writer.update(<unknown> this.transCollection.doc(
t.id),t);
it fails to compile:
error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'DocumentReference'.
It appears its impossible to do a batch write in angular-firestore,
but then again since there's no documentation,
maybe I'm just doing it wrong?