Skip to content

Commit 86d15b3

Browse files
committed
feat: enhance parameter dependency identification in schema generation
1 parent 4406d25 commit 86d15b3

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/schema/getSignatureSchema.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ export const getSignatureSchema = (
109109
: type
110110
)
111111

112-
// Identify parameter dependencies based on type parameters
113-
const funktionDependencies = getParameterDependencies(funktion!, nodeParameterTypes)
114-
115112
// Track which parameter slots actually carry a user-supplied value. The merge
116113
// uses this as a last-resort signal: if the function- and node-side schemas
117114
// both came out generic but the user did set something, the lift falls back
@@ -120,6 +117,9 @@ export const getSignatureSchema = (
120117
(p) => p?.value != null
121118
)
122119

120+
// Identify parameter dependencies based on type parameters
121+
const funktionDependencies = getParameterDependencies(funktion!, nodeParameterTypes, valueProvidedByIndex)
122+
123123
// Generate schema for each parameter
124124
const parameters = generateNodeSchemas(
125125
checker,
@@ -280,15 +280,19 @@ const extractFunctionParameterTypes = (
280280
/**
281281
* Identifies parameter dependencies based on shared type parameters.
282282
* Determines which parameters depend on type parameters declared in other parameters.
283-
* If an argument is explicitly provided (not null/undefined), it is not blocked.
283+
* A dependency is cleared once either the depended-on parameter carries a value
284+
* (so the shared type parameter is pinned by the user's choice) or the dependent
285+
* parameter's own argument already resolves to a concrete type.
284286
*
285287
* @param funktion - The function declaration to analyze
286288
* @param nodeParameterTypes
289+
* @param valueProvidedByIndex - Whether each parameter slot carries a user-supplied value
287290
* @returns Array of ParameterDependency objects
288291
*/
289292
const getParameterDependencies = (
290293
funktion: ts.FunctionDeclaration,
291-
nodeParameterTypes: ts.Type[] | undefined
294+
nodeParameterTypes: ts.Type[] | undefined,
295+
valueProvidedByIndex: boolean[] = [],
292296
): ParameterDependency[] => {
293297
const typeParamNames = funktion.typeParameters?.map((tp) => tp.name.getText()) || []
294298
const usage: Record<string, number[]> = {}
@@ -347,6 +351,11 @@ const getParameterDependencies = (
347351

348352
// Filter heraus, was durch echte Werte (nicht null/undefined) bereits aufgelöst ist
349353
return rawDependencies.filter((dep) => {
354+
// Providing the depended-on parameter pins the shared type parameter, so
355+
// the dependent is unblocked — even when the value carries no element type
356+
// to infer from (e.g. an empty list literal `[]`).
357+
if (valueProvidedByIndex[dep.dependsOnIndex]) return false
358+
350359
const resolvedType = nodeParameterTypes[dep.parameterIndex]
351360

352361
// Falls aus irgendeinem Grund kein Typ ermittelt werden konnte -> blocked lassen

0 commit comments

Comments
 (0)