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

isEqual type error when updating a nested object with converter #1793

Closed
VictorLeach96 opened this issue Oct 31, 2022 · 1 comment
Closed
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

@VictorLeach96
Copy link

Environment details

  • @google-cloud/firestore version: ^6.4.1

Steps to reproduce

Adding a nested object works correctly, however updating it will cause a type error.

import * as firestore from '@google-cloud/firestore'

const db = new firestore.Firestore()

interface Model {
  object: Record<string, { nested: boolean }>
}

const converter: firestore.FirestoreDataConverter<Model> = {
  fromFirestore: (snap: firestore.QueryDocumentSnapshot) => snap.data() as Model,
  toFirestore: (data: Model) => data
}

const main = async () => {
  const object: Record<string, { nested: boolean }> = {
    key: {
      nested: true
    }
  }

  const ref = await db.collection('').withConverter(converter).add({
    object
  })

  await ref.update({
    object
  })
}
main()

The following type error occurs on the update method.

Type 'Record<string, { nested: boolean; }>' is not assignable to type 'FieldValue | ({ [x: string]: FieldValue | { nested?: boolean | FieldValue | undefined; } | undefined; } & AddPrefixToKeys<string, { nested?: boolean | FieldValue | undefined; }>) | undefined'.
  Property 'isEqual' is missing in type 'Record<string, { nested: boolean; }>' but required in type 'FieldValue'.ts(2322)

firestore.d.ts(2230, 5): 'isEqual' is declared here.

test.ts(6, 3): The expected type comes from property 'object' which is declared here on type '{ object?: FieldValue | ({ [x: string]: FieldValue | { nested?: boolean | FieldValue | undefined; } | undefined; } & AddPrefixToKeys<string, { nested?: boolean | FieldValue | undefined; }>) | undefined; } & AddPrefixToKeys<...>'

The UpdateData type seems to be having trouble working correctly with objects and FieldValue.

@VictorLeach96 VictorLeach96 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 Oct 31, 2022
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Oct 31, 2022
@cherylEnkidu
Copy link
Contributor

Duplicate of #1745

Hi @VictorLeach96,

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

2 participants