Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing readonlyness
Browse files Browse the repository at this point in the history
RebeccaStevens committed Sep 13, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent da9774e commit 32bc77a
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/deepmerge.ts
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ function mergeUnknowns<

if (type === ObjectType.ARRAY) {
return utils.mergeFunctions.mergeArrays(
values as ReadonlyArray<unknown[]>,
values as ReadonlyArray<ReadonlyArray<unknown>>,
utils
) as DeepMergeHKT<Ts, MF>;
}
@@ -194,7 +194,7 @@ function mergeRecords<
* @param values - The arrays.
*/
function mergeArrays<
Ts extends ReadonlyArray<unknown[]>,
Ts extends ReadonlyArray<ReadonlyArray<unknown>>,
U extends DeepMergeMergeFunctionUtils,
MF extends DeepMergeMergeFunctionsURIs
>(values: Ts, utils: U) {
23 changes: 12 additions & 11 deletions src/types/merging.ts
Original file line number Diff line number Diff line change
@@ -153,14 +153,15 @@ export type DeepMergeLeafHKT<
/**
* Get the leaf type from many types that can't be merged.
*/
export type DeepMergeLeaf<Ts extends ReadonlyArray<unknown>> = Ts extends []
? never
: Ts extends [infer T]
? T
: Ts extends [...infer Rest, infer Tail]
? IsNever<Tail> extends true
? Rest extends ReadonlyArray<unknown>
? DeepMergeLeaf<Rest>
: never
: Tail
: never;
export type DeepMergeLeaf<Ts extends ReadonlyArray<unknown>> =
Ts extends readonly []
? never
: Ts extends [infer T]
? T
: Ts extends [...infer Rest, infer Tail]
? IsNever<Tail> extends true
? Rest extends ReadonlyArray<unknown>
? DeepMergeLeaf<Rest>
: never
: Tail
: never;
19 changes: 10 additions & 9 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ export type UnionSetValues<Ts extends ReadonlyArray<unknown>> =
export type UnionMapKeys<Ts extends ReadonlyArray<unknown>> =
Ts extends readonly [infer Head, ...infer Rest]
? Head extends Map<infer K1, unknown>
? Rest extends []
? Rest extends readonly []
? K1
: K1 | UnionMapKeys<Rest>
: never
@@ -184,7 +184,7 @@ export type UnionMapKeys<Ts extends ReadonlyArray<unknown>> =
export type UnionMapValues<Ts extends ReadonlyArray<unknown>> =
Ts extends readonly [infer Head, ...infer Rest]
? Head extends Map<unknown, infer V1>
? Rest extends []
? Rest extends readonly []
? V1
: UnionMapValues<Rest> | V1
: never
@@ -251,13 +251,14 @@ export type OptionalKeysOf<Ts extends readonly [unknown, ...unknown[]]> =
/**
* Filter out nevers from a tuple.
*/
export type FilterOutNever<T extends ReadonlyArray<unknown>> = T extends []
? []
: T extends [infer Head, ...infer Rest]
? IsNever<Head> extends true
? FilterOutNever<Rest>
: [Head, ...FilterOutNever<Rest>]
: T;
export type FilterOutNever<T extends ReadonlyArray<unknown>> =
T extends readonly []
? []
: T extends [infer Head, ...infer Rest]
? IsNever<Head> extends true
? FilterOutNever<Rest>
: [Head, ...FilterOutNever<Rest>]
: T;

/**
* Is the type a tuple?

0 comments on commit 32bc77a

Please sign in to comment.