@@ -34,24 +34,26 @@ export type Primitive = string | number | boolean | undefined | null;
34
34
export type NestedUpdateFields < T extends Record < string , unknown > > =
35
35
UnionToIntersection <
36
36
{
37
- // Check that T[K] extends Record to only allow nesting for map values.
38
- // Union with `undefined` to allow for optional nested fields
39
37
[ K in keyof T & string ] : ChildUpdateFields < T [ K ] , K > ;
40
38
} [ keyof T & string ] // Also include the generated prefix-string keys.
41
39
> ;
42
40
43
41
/**
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
45
43
* to distribute union types such as `undefined | {...}` (happens for optional
46
44
* 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
48
50
*/
49
- export type ChildUpdateFields < T , K extends string > =
51
+ export type ChildUpdateFields < T1 , K extends string > =
50
52
// Only allow nesting for map values
51
- T extends Record < string , unknown >
53
+ T1 extends Record < string , unknown >
52
54
? // Recurse into the map and add the prefix in front of each key
53
55
// (e.g. Prefix 'bar.' to create: 'bar.baz' and 'bar.qux'.
54
- AddPrefixToKeys < K , UpdateData < T > >
56
+ AddPrefixToKeys < K , UpdateData < T1 > >
55
57
: // UpdateData is always a map of values.
56
58
never ;
57
59
0 commit comments