From f164be7832cc0c304c943182c09f62921d927e43 Mon Sep 17 00:00:00 2001 From: mesqueeb Date: Mon, 14 Nov 2022 19:50:24 +0900 Subject: [PATCH] chore: build --- dist/types/merge.d.ts | 2 +- dist/types/typeUtils/Assign.d.ts | 6 ++--- dist/types/typeUtils/MergeDeep.d.ts | 37 ++++++++++++++--------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/dist/types/merge.d.ts b/dist/types/merge.d.ts index 2ad2188..2b0d0a6 100644 --- a/dist/types/merge.d.ts +++ b/dist/types/merge.d.ts @@ -6,7 +6,7 @@ import type { PrettyPrint } from './typeUtils/PrettyPrint'; * * This TS Utility can be used as standalone as well */ -export declare type Merge> = PrettyPrint>; +export declare type Merge, Ts extends List>> = PrettyPrint>; /** * Merge anything recursively. * Objects get merged, special objects (classes etc.) are re-assigned "as is". diff --git a/dist/types/typeUtils/Assign.d.ts b/dist/types/typeUtils/Assign.d.ts index b103119..7a0c835 100644 --- a/dist/types/typeUtils/Assign.d.ts +++ b/dist/types/typeUtils/Assign.d.ts @@ -34,8 +34,8 @@ declare type Cast = A1 extends A2 ? A1 : A2; * ``` */ declare type Extends = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0; -declare type __Assign, I extends Iteration = IterationOf<0>> = Extends, Length> extends 1 ? O : __Assign]>, Os, Next>; -declare type _Assign> = __Assign extends infer X ? Cast : never; +declare type __Assign, Os extends List>, I extends Iteration = IterationOf<0>> = Extends, Length> extends 1 ? O : __Assign]>, Os, Next>; +declare type _Assign, Os extends List>> = __Assign extends infer X ? Cast> : never; /** * Assign a list of [[Object]] into `O` with [[MergeDeep]]. Merges from right to * left, first items get overridden by the next ones (last-in overrides). @@ -46,5 +46,5 @@ declare type _Assign> = __Assign> = O extends unknown ? Os extends unknown ? _Assign : never : never; +export declare type Assign, Os extends List>> = O extends unknown ? (Os extends unknown ? _Assign : never) : never; export {}; diff --git a/dist/types/typeUtils/MergeDeep.d.ts b/dist/types/typeUtils/MergeDeep.d.ts index e2da231..10e0f0e 100644 --- a/dist/types/typeUtils/MergeDeep.d.ts +++ b/dist/types/typeUtils/MergeDeep.d.ts @@ -1,30 +1,29 @@ /** - * Make an object properties (all) `never`. We use this to intersect `object`s and - * preserve the combine modifiers like `+readonly` and `?optional`. + * Get the keys of `O` that are optional + * @param O + * @returns [[Key]] + * @example + * ```ts + * ``` */ -declare type Anyfy = { - [K in keyof O]: any; -}; +declare type OptionalKeys = O extends unknown ? { + [K in keyof O]-?: {} extends Pick ? K : never; +}[keyof O] : never; /** - * Get in `O` the type of a field of key `K` - * @param O to extract from - * @param K to extract at - * @returns [[Any]] + * Get the keys of `O` that are required + * @param O + * @returns [[Key]] * @example * ```ts - * type User = { - * info: { name: string; age: number; payment: {} } - * id: number - * } - * - * type test0 = At // number * ``` */ -declare type At = unknown extends A ? unknown : K extends keyof A ? A[K] : undefined; +declare type RequiredKeys = O extends unknown ? { + [K in keyof O]-?: {} extends Pick ? never : K; +}[keyof O] : never; declare type MergeObjectDeeply, O1 extends Record> = { - [K in keyof (Anyfy & O1)]: K extends keyof O1 ? MergeObjectOrReturnValue, At> : O[K]; + [K in keyof (O & O1)]: K extends RequiredKeys ? O1[K] : K extends OptionalKeys ? K extends OptionalKeys ? MergeObjectOrReturnUnion, Exclude> : K extends RequiredKeys ? Exclude extends O[K] ? O[K] : MergeObjectOrReturnUnion> : O1[K] : O[K]; }; -declare type MergeObjectOrReturnValue = [O1K] extends [never] ? OK : OK extends Record ? O1K extends Record ? MergeObjectDeeply : O1K : O1K; +declare type MergeObjectOrReturnUnion = Val0 extends Record ? Val1 extends Record ? MergeObjectDeeply : Val0 | Val1 : Val0 | Val1; /** * Accurately merge the fields of `O` with the ones of `O1`. It is * equivalent to the spread operator in JavaScript. [[Union]]s and [[Optional]] @@ -63,5 +62,5 @@ declare type MergeObjectOrReturnValue = [O1K] extends [never] ? OK : OK * // } * ``` */ -export declare type MergeDeep = O extends unknown ? O1 extends unknown ? MergeObjectOrReturnValue : never : never; +export declare type MergeDeep, O1 extends Record> = O extends unknown ? (O1 extends unknown ? MergeObjectDeeply : never) : never; export {};