Currently, I'm encountering a problem when attempting to update a Firestore document by adding an element to an array field using Firestore's 'arrayUnion' method. My Angular application is integrated with Firestore through AngularFire, and the specific error message I am facing states:
Type 'FieldValue' is missing the following properties from type 'CarAttachment[]': length, pop, push, concat
The expected type is derived from the property 'attachments,' which is defined within the 'Partial' type.
Below is the snippet of code relevant to this issue:
addCarAttachment(carId: string, attachment: CarAttachment) {
return this.firestore.collection<Car>('car').doc(carId).update({
attachments: FieldValue.arrayUnion(attachment),
});
}
In addition, I have created interfaces for both 'Car' and 'CarAttachment':
export interface Car {
id: string;
attachments: CarAttachment[];
created_at: Date | Timestamp;
updated_at?: Date | Timestamp;
}
export interface CarAttachment {
doc_name: string;
doc_url: string;
doc_type: string;
expiration_time: Date | Timestamp;
uploaded_at: Date | Timestamp;
}
I am looking for advice or solutions that can help me resolve this error and successfully update my Firestore document by adding an element to the 'attachments' array field using 'arrayUnion' while utilizing AngularFire.