Skip to content

AFS document update type error and custom object error #1215

Closed
@codediodeio

Description

@codediodeio

Issue

  1. Firestore doc update method raises a type error when passing individual properties.
  2. This method will also raise an error on custom JS objects.

screen shot 2017-10-05 at 6 56 56 am

Version info

AngularFire 5.0.0

Steps to Reproduce

/// 1. Type error issue
interface IUser {
  name: string;
  age: number;
}

const userDoc: AngularFirestoreDocument<IUser> = this.afs.doc('user/someId') ;

userDoc.update({ name: 'someName' }) /// not assignable to type IUser

/// 2. Custom object error issue

class User {
  constructor(public name: string, public age: number){}
}

userDoc.update(new User('hello', 23) )  /// invalid data error

Expected behavior

  1. No type error when passing individual params to update
  2. No errors when passing custom JS objects to update.

Proposed fix: remove generic and add spread to data argument in firestore/document.ts

  /**
   * Update some fields of a document without overwriting the entire document.
   * @param data
   */
  update(data): Promise<void> {
    return this.ref.update({ ...data });
  }

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