firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Typescript errors TS2345 on update method

Open dalepo opened this issue 2 years ago • 1 comments

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Ubuntu 22.04
  • Firebase SDK version: 11.11.0
  • Firebase Product: firebase-admin
  • Node.js version: 18
  • NPM version: 9.7.2

[REQUIRED] Step 3: Describe the problem

DocumentSnapshot or DocumentReference update method can't be used with typed interfaces. I get the following typescript error

TS2345: Argument of type  MyInterface  is not assignable to parameter of type

{ [x: string]: any; } & AddPrefixToKeys<string, any>

Relevant Code:

Calls like this will get errors:

const data = snapshot.data() as MyInterface;
db.collection(`anypath`).doc(id).update(data)

Quick workaround would be to cast it as any

db.collection(`anypath`).doc(id).update(data as any)

But it would require to refactor every update call which can be painful for large projects.

dalepo avatar Nov 15 '23 23:11 dalepo

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Nov 15 '23 23:11 google-oss-bot