From 6bfd06cafb29749542f835a08ccc54fbbba049ba Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Wed, 18 Oct 2023 15:22:21 +0200 Subject: [PATCH] feat: extract generic parameter from the reflectedType (see #18) --- src/core/parseReflectedType.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/parseReflectedType.ts b/src/core/parseReflectedType.ts index a2e9866..6212320 100644 --- a/src/core/parseReflectedType.ts +++ b/src/core/parseReflectedType.ts @@ -11,6 +11,7 @@ export type FunctionDef = { export type ImplementationDef = { fn: FunctionDef, dependencies: Record + genericParameter: string | null } /** @@ -23,6 +24,11 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim) const fn = parseAlias(name, fnsClause) + // extract the generic parameter like '' at the start of the type + const genericParameter = factoryArgs.trim().startsWith('<') + ? findBlockContents(factoryArgs, '<', '>')?.innerText || null + : null + const factoryArgsInner = findBlockContents(factoryArgs, '(', ')') const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1] const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : [] @@ -39,7 +45,7 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme const dependencies: Record = groupBy(deps, 'name') - return {fn, dependencies} + return {fn, dependencies, genericParameter } } function parseDependencies(deps: string): FunctionDef[] {