hkts icon indicating copy to clipboard operation
hkts copied to clipboard

Why specialize to 10 arguments?

Open reverofevil opened this issue 5 years ago • 5 comments

I think something in lines of

type Head<T extends any[]> = T extends [infer X, ...any[]] ? X : never;

type Tail<T extends any[]> = ((...x: T) => void) extends ((x: any, ...xs: infer XS) => void) ? XS : never

type Cons<X, XS extends any[]> = ((h: X, ...args: XS) => void) extends ((...args: infer R) => void) ? R : [];

type Reverse<L extends any[], X extends any[] = []> = (
	L extends [] ? { [indirect]: X } : { [indirect]: Reverse<Tail<L>, Cons<Head<L>, X>> }
)[typeof indirect];

// for some reason `indirect` hack doesn't work here
type MapTuple<X extends any[], S extends any[], R extends any[] = []> = {
	0: Reverse<R>,
	1: MapTuple<Tail<X>, S, Cons<$<Head<X>, S>, R>>
}[X extends [] ? 0 : 1]

type $<T, S extends any[]> = (
	T extends _<infer N> ? { [indirect]: S[N] } :
	T extends undefined | null | boolean | string | number ? { [indirect]: T } :
	T extends any[] ? { [indirect]: MapTuple<T, S> } :
	T extends (...x: infer I) => infer O ? { [indirect]: (...x: $<I, S>) => $<O, S> } :
	T extends object ? { [indirect]: { [K in keyof T]: $<T[K], S> } } :
	{ [indirect]: T }
)[typeof indirect];

should be possible to use.

reverofevil avatar Dec 25 '18 21:12 reverofevil