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 error when updating data with index signatures with an object as the value #1808

Closed
mrjoshua520 opened this issue Dec 28, 2022 · 3 comments
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mrjoshua520
Copy link

Environment details

  • OS: Windows 10
  • Node.js version: 18.12.1
  • npm version: 9.2.0
  • @google-cloud/firestore version: 6.4.1

Steps to reproduce

Here is the code giving the error

import { DocumentReference } from "@google-cloud/firestore";

type DocumentDataType = {
    [key: string]: {value: boolean};
}

function main(documentRef: DocumentReference<DocumentDataType>, data: DocumentDataType) {
    documentRef.update(data);
}

I've created this repository https://github.com/mrjoshua520/MinToReproduce-TransactionUpdateFieldValue/blob/main/index.ts

  1. Clone Repository
  2. Run npm ci
  3. Run npm run build

Here is the error that was obtained after following those steps

index.ts:8:24 - error TS2345: Argument of type 'DocumentDataType' is not assignable to parameter of type '{ [x: string]: FieldValue | { value?: boolean | FieldValue | undefined; } | undefined; } & AddPrefixToKeys<string, { value?: boolean | FieldValue | undefined; }>'.
  Type 'DocumentDataType' is not assignable to type 'AddPrefixToKeys<string, { value?: boolean | FieldValue | undefined; }>'.
    'string' and '`${string}.value`' index signatures are incompatible.
      Type '{ value: boolean; }' is not assignable to type 'boolean | FieldValue | undefined'.

8     documentRef.update(data);
                         ~~~~


Found 1 error in index.ts:8
@mrjoshua520 mrjoshua520 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 28, 2022
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Dec 28, 2022
mrjoshua520 added a commit to cat-acronym-team/cat-me-if-you-can that referenced this issue Dec 28, 2022
@nstringham
Copy link

We are using this workaround:

documentRef.update(data satisfies DocumentDataType as any);

@cherylEnkidu cherylEnkidu self-assigned this Dec 29, 2022
@cherylEnkidu
Copy link
Contributor

Hi,

Thank you for filling up the ticket! The team is not available for support during the holiday break and we will get back to you in the new year. Happy holiday!

@cherylEnkidu
Copy link
Contributor

Duplicate of #1745

Hi,

Thanks for filling the ticket! Our team is aware of this issue and is working on the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants