Skip to content

Commit 7633ff5

Browse files
author
Brian Chen
committed
update comments
1 parent 8865d09 commit 7633ff5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/firestore/src/lite-api/types.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,26 @@ export type Primitive = string | number | boolean | undefined | null;
3434
export type NestedUpdateFields<T extends Record<string, unknown>> =
3535
UnionToIntersection<
3636
{
37-
// Check that T[K] extends Record to only allow nesting for map values.
38-
// Union with `undefined` to allow for optional nested fields
3937
[K in keyof T & string]: ChildUpdateFields<T[K], K>;
4038
}[keyof T & string] // Also include the generated prefix-string keys.
4139
>;
4240

4341
/**
44-
* Helper for calculating the nested fields for a given type T. This is needed
42+
* Helper for calculating the nested fields for a given type T1. This is needed
4543
* to distribute union types such as `undefined | {...}` (happens for optional
4644
* props) or `{a: A} | {b: B}`.
47-
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
45+
*
46+
* In this use case, `T1` is used to distribute the union types of `T[K]` on
47+
* `Record`, since `T[K]` is evaluated as an expression and not distributed.
48+
*
49+
* See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
4850
*/
49-
export type ChildUpdateFields<T, K extends string> =
51+
export type ChildUpdateFields<T1, K extends string> =
5052
// Only allow nesting for map values
51-
T extends Record<string, unknown>
53+
T1 extends Record<string, unknown>
5254
? // Recurse into the map and add the prefix in front of each key
5355
// (e.g. Prefix 'bar.' to create: 'bar.baz' and 'bar.qux'.
54-
AddPrefixToKeys<K, UpdateData<T>>
56+
AddPrefixToKeys<K, UpdateData<T1>>
5557
: // UpdateData is always a map of values.
5658
never;
5759

packages/firestore/test/lite/integration.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ describe('withConverter() support', () => {
15921592
| {
15931593
requiredStr: string;
15941594
}
1595-
| { requiredStrObject: string };
1595+
| { requiredNumber: number };
15961596
}
15971597

15981598
const testConverterUnion = {
@@ -1624,20 +1624,22 @@ describe('withConverter() support', () => {
16241624
requiredStr: 'foo'
16251625
}
16261626
});
1627+
16271628
await updateDoc(testDocRef, {
16281629
'nested.requiredStr': 'foo'
16291630
});
16301631
await updateDoc(testDocRef, {
16311632
// @ts-expect-error
16321633
'nested.requiredStr': 1
16331634
});
1635+
16341636
await updateDoc(testDocRef, {
1635-
'nested.requiredStrObject': 'foo'
1637+
'nested.requiredNumber': 1
16361638
});
16371639

16381640
await updateDoc(testDocRef, {
16391641
// @ts-expect-error
1640-
'nested.requiredStringObject': 1
1642+
'nested.requiredNumber': 'foo'
16411643
});
16421644
});
16431645
});

0 commit comments

Comments
 (0)