Skip to content

arrayUnion() throws "FieldValue is missing..." error #2008

@bonjourclaudio

Description

@bonjourclaudio

Version info

Angular: 7.2.0

Firebase: 5.8.2

AngularFire: 5.1.1


I am trying to update an array "likedPosts" for a User-Document:

User Model:

export interface User {
  uid: string;
  email: string;
  photoURL?: string;
  displayName?: string;
  likedPosts?: string[];
  createdPosts?: string[];
}

Update array:

const userRef: AngularFirestoreDocument<User> = this.afs.doc(
      `users/${uid}`
);
userRef.update({
      likedPosts: firestore.FieldValue.arrayUnion("post23")
});

I am getting the following error:

[ts] Type 'FieldValue' is missing the following properties from type 'string[]': length, pop, push, concat, and 26 more. [2740]
User.ts(6, 3): The expected type comes from property 'likedPosts' which is declared here on type 'Partial'

This is the example code from firebase.com:

var washingtonRef = db.collection("cities").doc("DC");

// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

// Atomically remove a region from the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayRemove("east_coast")
});
test.firestore.js

Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions