Skip to content

Commit

Permalink
chore: build
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Nov 14, 2022
1 parent 0b7f1bd commit f164be7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dist/types/merge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { PrettyPrint } from './typeUtils/PrettyPrint';
*
* This TS Utility can be used as standalone as well
*/
export declare type Merge<T extends object, Ts extends List<object>> = PrettyPrint<Assign<T, Ts>>;
export declare type Merge<T extends Record<string | number | symbol, unknown>, Ts extends List<Record<string | number | symbol, unknown>>> = PrettyPrint<Assign<T, Ts>>;
/**
* Merge anything recursively.
* Objects get merged, special objects (classes etc.) are re-assigned "as is".
Expand Down
6 changes: 3 additions & 3 deletions dist/types/typeUtils/Assign.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ declare type Cast<A1, A2> = A1 extends A2 ? A1 : A2;
* ```
*/
declare type Extends<A1, A2> = [A1] extends [never] ? 0 : A1 extends A2 ? 1 : 0;
declare type __Assign<O extends object, Os extends List<object>, I extends Iteration = IterationOf<0>> = Extends<Pos<I>, Length<Os>> extends 1 ? O : __Assign<MergeDeep<O, Os[Pos<I>]>, Os, Next<I>>;
declare type _Assign<O extends object, Os extends List<object>> = __Assign<O, Os> extends infer X ? Cast<X, object> : never;
declare type __Assign<O extends Record<string | number | symbol, unknown>, Os extends List<Record<string | number | symbol, unknown>>, I extends Iteration = IterationOf<0>> = Extends<Pos<I>, Length<Os>> extends 1 ? O : __Assign<MergeDeep<O, Os[Pos<I>]>, Os, Next<I>>;
declare type _Assign<O extends Record<string | number | symbol, unknown>, Os extends List<Record<string | number | symbol, unknown>>> = __Assign<O, Os> extends infer X ? Cast<X, Record<string | number | symbol, unknown>> : 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).
Expand All @@ -46,5 +46,5 @@ declare type _Assign<O extends object, Os extends List<object>> = __Assign<O, Os
* ```ts
* ```
*/
export declare type Assign<O extends object, Os extends List<object>> = O extends unknown ? Os extends unknown ? _Assign<O, Os> : never : never;
export declare type Assign<O extends Record<string | number | symbol, unknown>, Os extends List<Record<string | number | symbol, unknown>>> = O extends unknown ? (Os extends unknown ? _Assign<O, Os> : never) : never;
export {};
37 changes: 18 additions & 19 deletions dist/types/typeUtils/MergeDeep.d.ts
Original file line number Diff line number Diff line change
@@ -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<O extends object> = {
[K in keyof O]: any;
};
declare type OptionalKeys<O extends object> = O extends unknown ? {
[K in keyof O]-?: {} extends Pick<O, K> ? 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<User, 'id'> // number
* ```
*/
declare type At<A, K extends string | number | symbol> = unknown extends A ? unknown : K extends keyof A ? A[K] : undefined;
declare type RequiredKeys<O extends object> = O extends unknown ? {
[K in keyof O]-?: {} extends Pick<O, K> ? never : K;
}[keyof O] : never;
declare type MergeObjectDeeply<O extends Record<string | number | symbol, unknown>, O1 extends Record<string | number | symbol, unknown>> = {
[K in keyof (Anyfy<O> & O1)]: K extends keyof O1 ? MergeObjectOrReturnValue<At<O, K>, At<O1, K>> : O[K];
[K in keyof (O & O1)]: K extends RequiredKeys<O1> ? O1[K] : K extends OptionalKeys<O1> ? K extends OptionalKeys<O> ? MergeObjectOrReturnUnion<Exclude<O[K], undefined>, Exclude<O1[K], undefined>> : K extends RequiredKeys<O> ? Exclude<O1[K], undefined> extends O[K] ? O[K] : MergeObjectOrReturnUnion<O[K], Exclude<O1[K], undefined>> : O1[K] : O[K];
};
declare type MergeObjectOrReturnValue<OK, O1K> = [O1K] extends [never] ? OK : OK extends Record<string | number | symbol, unknown> ? O1K extends Record<string | number | symbol, unknown> ? MergeObjectDeeply<OK, O1K> : O1K : O1K;
declare type MergeObjectOrReturnUnion<Val0, Val1> = Val0 extends Record<string | number | symbol, unknown> ? Val1 extends Record<string | number | symbol, unknown> ? MergeObjectDeeply<Val0, Val1> : 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]]
Expand Down Expand Up @@ -63,5 +62,5 @@ declare type MergeObjectOrReturnValue<OK, O1K> = [O1K] extends [never] ? OK : OK
* // }
* ```
*/
export declare type MergeDeep<O extends object, O1 extends object> = O extends unknown ? O1 extends unknown ? MergeObjectOrReturnValue<O, O1> : never : never;
export declare type MergeDeep<O extends Record<string | number | symbol, unknown>, O1 extends Record<string | number | symbol, unknown>> = O extends unknown ? (O1 extends unknown ? MergeObjectDeeply<O, O1> : never) : never;
export {};

0 comments on commit f164be7

Please sign in to comment.