Skip to content

Commit ab0fabb

Browse files
committed
feat: widen type resolution for conditional types in getSignatureSchema
1 parent 469286e commit ab0fabb

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/schema/getSignatureSchema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ const widenForSuggestions = (checker: ts.TypeChecker, type: ts.Type, node: ts.Va
393393
return checker.getAnyType()
394394
}
395395

396+
// A conditional type that still depends on a free type parameter cannot be
397+
// resolved to a single branch for suggestion scoping (e.g.
398+
// HTTP_PAYLOAD<S> = S extends 'application/json' ? OBJECT<{}> : … stays
399+
// unresolved while S is free, and isTypeAssignableTo against it is always
400+
// false). Its base constraint is the union of every branch
401+
// (string | OBJECT<{}> | undefined) — exactly the set of values the function
402+
// could accept here — so widen to that.
403+
if ((type.flags & ts.TypeFlags.Conditional) !== 0) {
404+
return checker.getBaseConstraintOfType(type) ?? checker.getAnyType()
405+
}
406+
396407
if ((type.flags & ts.TypeFlags.Object) !== 0 && hasFreeTypeParam(type, checker, new Set())) {
397408
const aliasName: string | undefined = (type as any).aliasSymbol?.getName()
398409
if (aliasName) {

0 commit comments

Comments
 (0)