From 722ee05a0a480aeb7ac9e59eeaacdfd164e3d66b Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Thu, 14 Sep 2023 14:51:49 +0200 Subject: [PATCH] resolve any number of arguments --- src/infer.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/infer.ts b/src/infer.ts index baf3d0c..7071c7b 100644 --- a/src/infer.ts +++ b/src/infer.ts @@ -36,21 +36,21 @@ function createFactory>() { type ResolveType = BaseTypes[T] - type ResolveTuple = - T extends K ? [ResolveType] : - T extends `${infer L extends K}, ${infer M extends K}` ? [ResolveType, ResolveType] : - T extends `${infer L extends K}, ${infer M extends K}, ${infer N extends K}` - ? [ResolveType, ResolveType, ResolveType] - : never + type ResolveArguments = + S extends '' ? [] : + S extends `${infer T extends K}, ${infer U}` + ? [ResolveType, ...ResolveArguments] + : S extends `${infer T extends K}` ? [ResolveType] + : never; - type ResolveFunction = + type ResolveFunctionDef = T extends `${infer Name}(${infer Args}) : ${infer L extends K}` - ? (...args: ResolveTuple) => ResolveType + ? (...args: ResolveArguments) => ResolveType : never return function create( dependencies: { [L in T]: U }, - callback: (deps: { [L in T]: ResolveFunction }) => V + callback: (deps: { [L in T]: ResolveFunctionDef }) => V ) { return callback }