resolve any number of arguments
This commit is contained in:
parent
11792e0435
commit
722ee05a0a
18
src/infer.ts
18
src/infer.ts
@ -36,21 +36,21 @@ function createFactory<BaseTypes extends Record<string, unknown>>() {
|
||||
|
||||
type ResolveType<T extends K> = BaseTypes[T]
|
||||
|
||||
type ResolveTuple<T> =
|
||||
T extends K ? [ResolveType<T>] :
|
||||
T extends `${infer L extends K}, ${infer M extends K}` ? [ResolveType<L>, ResolveType<M>] :
|
||||
T extends `${infer L extends K}, ${infer M extends K}, ${infer N extends K}`
|
||||
? [ResolveType<L>, ResolveType<M>, ResolveType<N>]
|
||||
: never
|
||||
type ResolveArguments<S extends string> =
|
||||
S extends '' ? [] :
|
||||
S extends `${infer T extends K}, ${infer U}`
|
||||
? [ResolveType<T>, ...ResolveArguments<U>]
|
||||
: S extends `${infer T extends K}` ? [ResolveType<T>]
|
||||
: never;
|
||||
|
||||
type ResolveFunction<T> =
|
||||
type ResolveFunctionDef<T> =
|
||||
T extends `${infer Name}(${infer Args}) : ${infer L extends K}`
|
||||
? (...args: ResolveTuple<Args>) => ResolveType<L>
|
||||
? (...args: ResolveArguments<Args>) => ResolveType<L>
|
||||
: never
|
||||
|
||||
return function create<T extends string, U extends string, V>(
|
||||
dependencies: { [L in T]: U },
|
||||
callback: (deps: { [L in T]: ResolveFunction<U> }) => V
|
||||
callback: (deps: { [L in T]: ResolveFunctionDef<U> }) => V
|
||||
) {
|
||||
return callback
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user