Description
[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 commentedon Mar 29, 2022
I have the same issue.
ebeloded commentedon Apr 28, 2022
Any updates on this issue? The current implementation of
UpdateData
type doesn't allow working with complex objects in a type-safe manner.ehsannas commentedon May 11, 2022
Hi everyone, sorry for the delay. I'll try to prioritize the investigation for this issue.
ehsannas commentedon May 25, 2022
Hi everyone, sorry for the wait and for the trouble. Do you currently have a workaround for this (e.g. using
any
)?ebeloded commentedon May 26, 2022
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 commentedon May 27, 2022
Same.
nwaughachukwuma commentedon Jun 21, 2022
Hi @ehsannas, I opened a PR in #6371 to fix this issue. Please follow-up
dconeybe commentedon Nov 10, 2022
This is a duplicate of #5853. Please follow that issue for updates.
dconeybe commentedon 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