-
Notifications
You must be signed in to change notification settings - Fork 148
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
DocumentReference<T>.update() is wrongly parameterized #1745
Comments
Thank you for bringing this to our attention. I will take a closer look. |
Any news on this? It is blocking our firebase-admin upgrade. |
Option 2 would be wonderful here, IMO. |
There's another issue with the UpdateData typing as well, it can't handle mapped types. Environment:
Given this type as a model for the data:
The UpdateData type doesn't accurately reflect allowed values:
resulting in:
The To accurately parse this construct Typescript would need to have regex or similar typing that can narrow down |
@PieterDexper This is exactly our problem too. We ended up using really suboptimal way to resolve it: // TODO: FIXME: DELETE as any CAST WHEN TYPES ARE FIXED!
...update(valueObject as any) Fortunately we have only handful of these for now, so it's manageable. |
(And while we're at it, could we please have |
@swftvsn Can you please open a separate issue to request |
@dconeybe Sorry to bump this but could you give us a rough estimation on when/if this will be approached further? |
@FBuervenich, I can't give a commitment or a timeline to deliver this. However, we have been investigating it. I will say that it needs to be treated as a breaking change and included in a major version release. |
Good to know I'm not the only one. Luckily I can use |
I ran into this problem, too. Neither the function docs nor published documentation mention this limitation, which can affect the consistency of data in the DB! I highly recommend updating the docs to mention this limitation. |
Do we have to wait for the fix made in |
Yes. We are planning to have the change released here in the coming months, but, unfortunately, it's not our top priority and we cannot promise any specific release date. We also have to release it carefully because it is a "breaking API change" and requires a major version upgrade. We will post here once the fix is released. |
Looks like a fix for this was pushed out, but I'm still getting an error when assigning a whole object to the property. Type 'Record<string, { id: string; }>' is not assignable to type 'FieldValue | ({ [x: string]: { id?: string | FieldValue | undefined; } | FieldValue | undefined; } & AddPrefixToKeys<string, { id?: string | FieldValue | undefined; }>) | undefined'.
Property 'isEqual' is missing in type 'Record<string, { id: string; }>' but required in type 'FieldValue'. const update: firestore.UpdateData<{ prop: Record<string, { id: string }> }> = {}
const value: Record<string, { id: string }> = {
key: { id: '' }
}
update.prop = value |
This issue was fixed in commit #1887 and released in v7.0.0.
The |
@VictorLeach96, the issue you reported using |
Environment details
@google-cloud/firestore
version: 5.0.2Issue description
In #1595, the type of the DocumentReference.update() method was updated to get a
UpdateData<T>
instead of the previously unparameterizedUpdateData
.This was presumably done to make the method type-safe and more consistent with get() and set() methods.
However, the parameter
T
does not refer to the database format of the objects, but to the "converted" format that is returned by the converter'sfromFirestore
method (if any is configured). While this makes sense for get() and set(), since they call the appropriate converter methods, the same does not hold true for the update() method. The update() method does not call the configured converter, and instead operates directly on the database values (see reference#update() which delegates to write-batch#update).This means that the newly introduced parameter to UpdateData should reflect the storage format of the collection, not the mapped type defined by the converter.
Unfortunately, such a type is currently not present in the library's types.
Demonstration
To demonstrate the issue, consider this fictitious collection where the data is stored as an object with a
count: number
property, but the converter converts it to aprogress: string
consisting ofcount
asterisks:Now let's operate on a document
foo
in that collection:Setting works as expected
Setting only the progress property to a new value (with merge:true) works just as well:
Using a increment on the property works just the same, even though it sounds a bit strange to increase the progress, but the converter hands that through to the count property:
The database entry now contains a property
progress
, which should not exist on that level.Proposed solution:
and/or
or
The text was updated successfully, but these errors were encountered: