File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,13 @@ export function getObjectDefinition(
8787}
8888
8989function 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 ,
You can’t perform that action at this time.
0 commit comments