feat: extract generic parameter from the reflectedType (see #18)

This commit is contained in:
Jos de Jong 2023-10-18 15:22:21 +02:00
parent 0cdc9aba78
commit 6bfd06cafb

View File

@ -11,6 +11,7 @@ export type FunctionDef = {
export type ImplementationDef = {
fn: FunctionDef,
dependencies: Record<string, FunctionDef>
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 '<T>' 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<string, FunctionDef> = groupBy(deps, 'name')
return {fn, dependencies}
return {fn, dependencies, genericParameter }
}
function parseDependencies(deps: string): FunctionDef[] {