Skip to content

Support union types and optional fields with dot separation on UpdateData #5394

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

Merged
merged 13 commits into from
Sep 20, 2021
5 changes: 5 additions & 0 deletions .changeset/clean-cameras-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': minor
---

Fixed a bug where UpdateData did not recognize optional, dot-separated string fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this goes straight into release notes, I'd suggest UpdateData as a literal, and a period. Otherwise LGTM, thanks!

4 changes: 2 additions & 2 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export { LogLevel }

// @public
export type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
[K in keyof T & string]: T[K] extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<T[K]>> : never;
[K in keyof T & string]: T[K] extends Record<string, unknown> | undefined ? AddPrefixToKeys<K, UpdateData<T[K]>> : never;
}[keyof T & string]>;

// @public
Expand Down Expand Up @@ -332,7 +332,7 @@ export class Transaction {
export type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

// @public
export type UpdateData<T> = T extends Primitive ? T : T extends Map<infer K, infer V> ? Map<UpdateData<K>, UpdateData<V>> : T extends {} ? {
export type UpdateData<T> = T extends undefined ? never : T extends Primitive ? T : T extends {} ? {
[K in keyof T]?: UpdateData<T[K]> | FieldValue;
} & NestedUpdateFields<T> : Partial<T>;

Expand Down
Loading