Skip to content

Commit 3e84354

Browse files
committed
fix: display clean string literal values without quotes in docs
1 parent 0b01bad commit 3e84354

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/components/object-definition.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ export function getObjectDefinition(
8787
}
8888

8989
function getPrimitiveType(type: ts.UnionOrIntersectionType) {
90-
if (type.types.every(subtype => subtype.isStringLiteral())) {
90+
if (type.types.every(subtype => subtype.isStringLiteral() || (subtype.flags & ts.TypeFlags.StringLiteral))) {
9191
return 'string';
9292
}
93-
if (type.types.every(subtype => subtype.isNumberLiteral())) {
93+
if (type.types.every(subtype => subtype.isNumberLiteral() || (subtype.flags & ts.TypeFlags.NumberLiteral))) {
9494
return 'number';
9595
}
96+
9697
return undefined;
9798
}
9899

@@ -104,9 +105,12 @@ function getUnionTypeDefinition(
104105
): { type: string; inlineType: UnionTypeDefinition } {
105106
const valueDescriptions = extractValueDescriptions(realType, typeNode);
106107
const primitiveType = getPrimitiveType(realType);
107-
const values = realType.types.map(subtype =>
108-
primitiveType ? (subtype as ts.LiteralType).value.toString() : stringifyType(subtype, checker)
109-
);
108+
const values = realType.types.map(subtype => {
109+
if (primitiveType && subtype.isStringLiteral()) {
110+
return (subtype as ts.LiteralType).value.toString();
111+
}
112+
return stringifyType(subtype, checker);
113+
});
110114

111115
return {
112116
type: primitiveType ?? realTypeName,

0 commit comments

Comments
 (0)