[SOLVED] How to import WriteBatch from Firebase in Angular>

Issue

I’m using this packages to handle Firebase in my Angular App:

"@angular/fire": "^6.1.4",
"firebase": "^8.2.7",

I created a service to handle Batch operations:

import { WriteBatch } from 'firebase/firestore'; // Does not work
import { WriteBatch } from 'firebase'; // Does not work

export class FireStoreBatch {
  private _batch: WriteBatch;

  public Create(): void{
    this._batch = this.afs.firestore.batch();
  }

}

enter image description here

Which import do I need to add to be able to use WriteBatch?

Solution

I came across the same problem, as I wanted to pass the WriteBatch as a parameter to a function. I did not find a fitting import, but was able to pass the WriteBatch using FirebaseFirestore.WriteBatch.

export const myFunction = (batch: FirebaseFirestore.WriteBatch) => {
  // do something
}

Just by the look of it, this should also work for your code:

export class FireStoreBatch {
  private _batch: FirebaseFirestore.WriteBatch;

  public Create(): void{
    this._batch = this.afs.firestore.batch();
  }

}

Answered By – elpair

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *