1 | import type { UnknownFunction, Expand, TuplifyUnion, Has, List, IsTuple } from '../types';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type MergeParameters<T extends readonly UnknownFunction[], ParamsArrays extends readonly any[][] = ExtractParams<T>, TransposedArrays = Transpose<ParamsArrays>, TuplifiedArrays extends any[] = TuplifyUnion<TransposedArrays>, LongestParamsArray extends readonly any[] = LongestArray<TuplifiedArrays>> = ExpandItems<RemoveNames<{
|
7 | [index in keyof LongestParamsArray]: LongestParamsArray[index] extends LongestParamsArray[number] ? IgnoreInvalidIntersections<IntersectAll<LongestParamsArray[index]>> : never;
|
8 | }>>;
|
9 |
|
10 | type EmptyObject = {
|
11 | [K in any]: never;
|
12 | };
|
13 | type IgnoreInvalidIntersections<T> = T extends EmptyObject ? never : T;
|
14 |
|
15 | export type ExtractParams<T extends readonly UnknownFunction[]> = {
|
16 | [index in keyof T]: T[index] extends T[number] ? Parameters<T[index]> : never;
|
17 | };
|
18 |
|
19 | export type ExpandItems<T extends readonly unknown[]> = {
|
20 | [index in keyof T]: T[index] extends T[number] ? Expand<T[index]> : never;
|
21 | };
|
22 |
|
23 | export type Longest<L extends List, L1 extends List> = L extends unknown ? L1 extends unknown ? {
|
24 | 0: L1;
|
25 | 1: L;
|
26 | }[Has<keyof L, keyof L1>] : never : never;
|
27 |
|
28 |
|
29 |
|
30 | export type LongestArray<S extends readonly any[][]> = IsTuple<S> extends '0' ? S[0] : S extends [any[], any[]] ? Longest<S[0], S[1]> : S extends [any[], any[], ...infer Rest] ? Longest<Longest<S[0], S[1]>, Rest extends any[][] ? LongestArray<Rest> : []> : S extends [any[]] ? S[0] : never;
|
31 |
|
32 |
|
33 | export type IntersectAll<T extends any[]> = IsTuple<T> extends '0' ? T[0] : _IntersectAll<T>;
|
34 | type IfJustNullish<T, True, False> = [T] extends [undefined | null] ? True : False;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | type _IntersectAll<T, R = unknown> = T extends [infer First, ...infer Rest] ? _IntersectAll<Rest, IfJustNullish<First, R, R & First>> : R;
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | type RemoveNames<T extends readonly any[]> = [any, ...T] extends [
|
49 | any,
|
50 | ...infer U
|
51 | ] ? U : never;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | type Transpose<T> = T[Extract<keyof T, T extends readonly any[] ? number : unknown>] extends infer V ? {
|
57 | [K in keyof V]: {
|
58 | [L in keyof T]: K extends keyof T[L] ? T[L][K] : undefined;
|
59 | };
|
60 | } : never;
|
61 | export {};
|