Skip to content

Commit

Permalink
fix: handling of partial types
Browse files Browse the repository at this point in the history
fix #476
  • Loading branch information
RebeccaStevens committed May 21, 2024
1 parent 65658c8 commit 1832bd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/types/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ export type DeepMergeFunctionsDefaultURIs = Readonly<{
DeepMergeFilterValuesURI: DeepMergeFilterValuesDefaultURI;
}>;

type RecordEntries<T extends Record<PropertyKey, unknown>> = TuplifyUnion<
{
[K in keyof T]: [K, T[K]];
}[keyof T]
type RecordEntries<T extends Record<PropertyKey, unknown>> = FilterOut<
TuplifyUnion<
{
[K in keyof T]: [K, T[K]];
}[keyof T]
>,
undefined
>;

type RecordMeta = Record<PropertyKey, RecordPropertyMeta>;
Expand All @@ -79,16 +82,13 @@ type RecordsToRecordMeta<
[I in keyof Ts]: RecordToRecordMeta<Ts[I]>;
}>;

type RecordToRecordMeta<T extends Record<PropertyKey, unknown>> =
object extends T
? never
: {
[K in keyof T]-?: {
key: K;
value: Required<T>[K];
optional: KeyIsOptional<K, T>;
};
};
type RecordToRecordMeta<T extends Record<PropertyKey, unknown>> = {
[K in keyof T]-?: {
key: K;
value: Required<T>[K];
optional: KeyIsOptional<K, T>;
};
};

/**
* Deep merge records.
Expand Down Expand Up @@ -119,9 +119,16 @@ type DeepMergeRecordMetaDefaultHKTProps<
type MergeRecordMeta<RecordMetas extends ReadonlyArray<RecordMeta>> =
GroupValuesByKey<
FlattenTuples<
TransposeTuple<{
[I in keyof RecordMetas]: TransposeTuple<RecordEntries<RecordMetas[I]>>;
}>
TransposeTuple<
FilterOut<
{
[I in keyof RecordMetas]: TransposeTuple<
RecordEntries<RecordMetas[I]>
>;
},
readonly []
>
>
>
>;

Expand Down
4 changes: 4 additions & 0 deletions tests/deepmerge.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,7 @@ expectType<undefined>(test21);

const test22 = deepmerge({} as any, {} as any);
expectType<unknown>(test22);

const r: { a?: string; b?: number; c?: boolean } = { a: "a", b: 1 };
const test23 = deepmerge(r, r);
expectType<{ a?: string; b?: number; c?: boolean }>(test23);

0 comments on commit 1832bd0

Please sign in to comment.