Skip to content

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

@nwaughachukwuma

Description

@nwaughachukwuma

[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 })

Activity

harshmandan

harshmandan commented on Mar 29, 2022

@harshmandan

I have the same issue.

self-assigned this
on Mar 29, 2022
ebeloded

ebeloded commented on Apr 28, 2022

@ebeloded

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

ehsannas

ehsannas commented on May 11, 2022

@ehsannas
Contributor

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

ehsannas

ehsannas commented on May 25, 2022

@ehsannas
Contributor

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

ebeloded

ebeloded commented on May 26, 2022

@ebeloded

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

nwaughachukwuma commented on May 27, 2022

@nwaughachukwuma
Author

Same.

nwaughachukwuma

nwaughachukwuma commented on Jun 21, 2022

@nwaughachukwuma
Author

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

dconeybe

dconeybe commented on Nov 10, 2022

@dconeybe
Contributor

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

locked and limited conversation to collaborators on Dec 11, 2022
dconeybe

dconeybe commented on Jul 7, 2023

@dconeybe
Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @MarkDuckworth@ehsannas@ebeloded@nwaughachukwuma@harshmandan

    Issue actions

      Issue with type UpdateData<T> from firebase/firestore · Issue #6105 · firebase/firebase-js-sdk