1 | import { ReverseHead, ReverseTail } from '../types';
|
2 | type UnknownFunction = (...args: any[]) => any;
|
3 | type LongestTuple<T> = T extends [infer U extends unknown[]] ? U : T extends [infer U, ...infer R extends unknown[][]] ? MostProperties<U, LongestTuple<R>> : never;
|
4 | type MostProperties<T, U> = keyof U extends keyof T ? T : U;
|
5 | type ElementAt<T, N extends keyof any> = N extends keyof T ? T[N] : unknown;
|
6 | type ElementsAt<T, N extends keyof any> = {
|
7 | [K in keyof T]: ElementAt<T[K], N>;
|
8 | };
|
9 | type Intersect<T extends readonly unknown[]> = T extends [] ? unknown : T extends [infer H, ...infer T] ? H & Intersect<T> : T[number];
|
10 | type MergeTuples<T, L extends unknown[] = LongestTuple<T>> = {
|
11 | [K in keyof L]: Intersect<ElementsAt<T, K> extends readonly unknown[] ? ElementsAt<T, K> : never>;
|
12 | };
|
13 | type ExtractParameters<T extends readonly UnknownFunction[]> = {
|
14 | [K in keyof T]: Parameters<T[K]>;
|
15 | };
|
16 | export type MergeParameters<T extends readonly UnknownFunction[]> = '0' extends keyof T ? MergeTuples<MakeRestExplicit<ExtractParameters<T>>> : Parameters<T[number]>;
|
17 | type HasRest<S extends readonly unknown[]> = number extends S['length'] ? true : false;
|
18 | type HasExplicit<S extends readonly unknown[]> = '0' extends keyof S ? true : false;
|
19 | type HasCombined<S extends readonly unknown[]> = true extends HasExplicit<S> & HasRest<S> ? true : false;
|
20 | type MakeRestExplicit<T extends readonly unknown[][]> = true extends HasCombined<T> ? [
|
21 | ...ReverseTail<T>,
|
22 | ReverseHead<T> extends readonly unknown[] ? ReverseHead<T>[number] : never
|
23 | ] : true extends HasRest<T> ? [...T] : T;
|
24 | export {};
|