Skip to content

Commit a44b014

Browse files
committed
feat: stripping away undefined for suggestions
1 parent 8ae52ff commit a44b014

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/util/schema.util.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export const getSchema = (
139139
// Collect all available suggestions for this parameter
140140
const combinedSuggestions = suggestions ? {
141141
suggestions: [
142-
...getValues(parameterType),
142+
...getValues(parameterType, checker),
143143
...(node ? getReferences(
144144
checker,
145145
node,
@@ -161,6 +161,19 @@ export const getSchema = (
161161
],
162162
} : {};
163163

164+
// Strip undefined from unions (e.g. string | undefined → string).
165+
// Suggestions are collected above from the original type (preserving aliasSymbol literals),
166+
// the base schema is determined from the stripped type, then both are merged.
167+
if (parameterType.isUnion()) {
168+
const nonUndefined = parameterType.types.filter(
169+
(t) => (t.flags & ts.TypeFlags.Undefined) === 0
170+
)
171+
if (nonUndefined.length === 1) {
172+
const baseSchema = getSchema(checker, node, nonUndefined[0], functionDeclarations, functions, false)
173+
return {...baseSchema, ...combinedSuggestions}
174+
}
175+
}
176+
164177
// Check individual primitive types
165178
if (isBoolean(parameterType)) {
166179
return {input: "boolean", ...combinedSuggestions};

0 commit comments

Comments
 (0)