Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript errors TS2345 on update method #2372

Open
dalepo opened this issue Nov 15, 2023 · 1 comment
Open

Typescript errors TS2345 on update method #2372

dalepo opened this issue Nov 15, 2023 · 1 comment

Comments

@dalepo
Copy link

dalepo commented Nov 15, 2023

[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.

@google-oss-bot
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants