Skip to content

Commit f78ceca

Browse files
author
Brian Chen
authored
Support union types and optional fields with dot separation on UpdateData (#5394)
1 parent c236221 commit f78ceca

File tree

8 files changed

+692
-534
lines changed

8 files changed

+692
-534
lines changed

.changeset/clean-cameras-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/firestore': minor
3+
---
4+
5+
Fixed a bug where `UpdateData` did not recognize union types or optional, dot-separated string fields.

common/api-review/firestore-lite.api.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export class Bytes {
3232
toUint8Array(): Uint8Array;
3333
}
3434

35+
// @public
36+
export type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;
37+
3538
// @public
3639
export function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData>;
3740

@@ -191,7 +194,7 @@ export { LogLevel }
191194

192195
// @public
193196
export type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
194-
[K in keyof T & string]: T[K] extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<T[K]>> : never;
197+
[K in keyof T & string]: ChildUpdateFields<K, T[K]>;
195198
}[keyof T & string]>;
196199

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

334337
// @public
335-
export type UpdateData<T> = T extends Primitive ? T : T extends Map<infer K, infer V> ? Map<UpdateData<K>, UpdateData<V>> : T extends {} ? {
338+
export type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
336339
[K in keyof T]?: UpdateData<T[K]> | FieldValue;
337340
} & NestedUpdateFields<T> : Partial<T>;
338341

0 commit comments

Comments
 (0)