angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

updateDoc should take any object as data

Open arnotixe opened this issue 3 years ago • 2 comments
trafficstars

Version info

Angular: 13.2.4

Firebase: 9.6.7

AngularFire: 7.2.1

**Other (e.g. Ionic/Cordova, Node, browser, operating system): ionic 6, node 12.22.6 on linux mint 20.2 **

How to reproduce these conditions

use updateDoc with an interfaced object:

updateEdit(sv: SkapVersion) {
    updateDoc(
      doc(this.firestore, `/databasepath/`),
      sv
    );
  }

Just casting the data parameter as any fixes the error:

updateEdit(sv: SkapVersion) {
    updateDoc(
      doc(this.firestore, `/databasepath/`),
      sv as any
    );
  }

Failing test unit, Stackblitz demonstrating the problem not really

Steps to set up and reproduce pass an object defined by an interface, to updateDoc() as in the examples above

Sample data and security rules sv = { test: true} as SkapVersion; and pass that => error

Debug output

** Errors in the JavaScript console ** Argument of type 'SkapVersion' is not assignable to parameter of type '{ [x: string]: any; } & AddPrefixToKeys<string, any>'.

** Output from firebase.database().enableLogging(true); **

** Screenshots ** vscode: image

Expected behavior

Expected updateDoc to take any object (like setDoc() and addDoc() do)

Actual behavior

Error "no overload matches this call."

arnotixe avatar Feb 21 '22 00:02 arnotixe

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Feb 21 '22 00:02 google-oss-bot

@arnotixe This can be fixed passing a new object like this: { ...myObjectTyped } instead of sv as SkapVersion, i´m not sure how good is allow pass any or generic type but this can be a solution...

NOTE for devs: For reproduce this error, you only need to add or update a document with a "custom type"

Skrigueztep avatar Apr 17 '22 20:04 Skrigueztep