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

Issue with type UpdateData<T> from firebase/firestore #6105

Closed
nwaughachukwuma opened this issue Mar 29, 2022 · 9 comments · Fixed by #7318 · May be fixed by #6371
Closed

Issue with type UpdateData<T> from firebase/firestore #6105

nwaughachukwuma opened this issue Mar 29, 2022 · 9 comments · Fixed by #7318 · May be fixed by #6371
Assignees

Comments

@nwaughachukwuma
Copy link

nwaughachukwuma commented Mar 29, 2022

[REQUIRED] Describe your environment

  • Operating System version: Mac OS
  • Browser version: N/A
  • Firebase SDK version: "firebase": "9.6.8", "firebase-admin": "10.0.2", "@firebase/rules-unit-testing": "2.0.2",
  • Firebase Product: Firestore

[REQUIRED] Describe the problem

Steps to reproduce:

There is an issue with type UpdateData<T> imported from firebase/firestore, which fails to properly parse object type when data is nested deeper than one level - i.e. it passes foo.bar but not foo.bar.baz. Given the data shape and ops in the relevant code section, I get the following error on my IDE and also when I build my project:

Argument of type '{ [x: string]: UserRole; }' is not assignable to parameter of type '{ members?: FieldValue | { [x: string]: FieldValue | { role?: UserRole | FieldValue | undefined; status?: MemberStatus | FieldValue | undefined; } | undefined; } | undefined; name?: string | ... 1 more ... | undefined; } & AddPrefixToKeys<...>'.
  Type '{ [x: string]: UserRole; }' is not assignable to type 'AddPrefixToKeys<"members", { [x: string]: FieldValue | { role?: UserRole | FieldValue | undefined; status?: MemberStatus | FieldValue | undefined; } | undefined; }>'.
    'string' and '`members.${string}`' index signatures are incompatible.
      Type 'UserRole' is not assignable to type 'FieldValue | { role?: UserRole | FieldValue | undefined; status?: MemberStatus | FieldValue | undefined; } | undefined'.

Relevant Code:

type UserID = string
enum UserRole {
  Admin = 'Admin',
  Member = 'Member',
}
type MemberStatus = 'pending' | 'active'
interface TeamMember {
  role: UserRole
  status: MemberStatus
}

/** 
* this works
*/
interface Team {
  name: string
  members: Record<UserID, UserRole>
}
Update Op:
~.update({ [`members.${uid}`]: UserRole.Member })

/** 
* this doesn't work
*/
interface Team {
  name: string
  members: Record<UserID, TeamMember> 
}
Update Op:
~.update({ [`members.${uid}.role`]: UserRole.Member })
@harshmandan
Copy link

I have the same issue.

@ehsannas ehsannas self-assigned this Mar 29, 2022
@ebeloded
Copy link

Any updates on this issue? The current implementation of UpdateData type doesn't allow working with complex objects in a type-safe manner.

@ehsannas
Copy link
Contributor

Hi everyone, sorry for the delay. I'll try to prioritize the investigation for this issue.

@ehsannas
Copy link
Contributor

Hi everyone, sorry for the wait and for the trouble. Do you currently have a workaround for this (e.g. using any)?

@ebeloded
Copy link

Hi @ehsannas. Thank you for check-in. Currently, we cover up some parts of data interfaces with any with an intention to update when the issue is resolved.

@nwaughachukwuma
Copy link
Author

Same.

@nwaughachukwuma
Copy link
Author

Hi @ehsannas, I opened a PR in #6371 to fix this issue. Please follow-up

@dconeybe dconeybe assigned MarkDuckworth and unassigned ehsannas Nov 10, 2022
@dconeybe
Copy link
Contributor

This is a duplicate of #5853. Please follow that issue for updates.

@firebase firebase locked and limited conversation to collaborators Dec 11, 2022
@dconeybe
Copy link
Contributor

dconeybe commented Jul 7, 2023

This is fixed in the v10.0.0 release: https://firebase.google.com/support/release-notes/js#version_1000_-_july_6_2023

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.