Skip to content

Commit

Permalink
Support union types and optional fields with dot separation on Update…
Browse files Browse the repository at this point in the history
…Data (#5394)
  • Loading branch information
Brian Chen committed Sep 20, 2021
1 parent c236221 commit f78ceca
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 534 deletions.
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 union types or optional, dot-separated string fields.
7 changes: 5 additions & 2 deletions common/api-review/firestore-lite.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class Bytes {
toUint8Array(): Uint8Array;
}

// @public
export type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;

// @public
export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;

Expand Down Expand Up @@ -191,7 +194,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]: ChildUpdateFields<K, T[K]>;
}[keyof T & string]>;

// @public
Expand Down Expand Up @@ -332,7 +335,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 Primitive ? T : T extends {} ? {
[K in keyof T]?: UpdateData<T[K]> | FieldValue;
} & NestedUpdateFields<T> : Partial<T>;

Expand Down

0 comments on commit f78ceca

Please sign in to comment.