File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class MyObject {
2- foo : "ok" | "fail" | "abort" ;
2+ foo : "ok" | "fail" | "abort" | "" ;
33 bar : "ok" | "fail" | "abort" | string ;
44}
Original file line number Diff line number Diff line change 66 },
77 "foo" : {
88 "enum" : [
9+ " " ,
910 " abort" ,
1011 " fail" ,
1112 " ok"
Original file line number Diff line number Diff line change 1- type result = "ok" | "fail" | "abort" ;
1+ type result = "ok" | "fail" | "abort" | "" ;
22
33class MyObject {
44 foo : result ;
Original file line number Diff line number Diff line change 33 "definitions" : {
44 "result" : {
55 "enum" : [
6+ " " ,
67 " abort" ,
78 " fail" ,
89 " ok"
Original file line number Diff line number Diff line change @@ -236,15 +236,18 @@ export class JsonSchemaGenerator {
236236 }
237237
238238 private extractLiteralValue ( typ : ts . Type ) : PrimitiveType | undefined {
239+ let str = ( < ts . LiteralType > typ ) . value ;
240+ if ( str === undefined ) {
241+ str = ( typ as any ) . text ;
242+ }
239243 if ( typ . flags & ts . TypeFlags . EnumLiteral ) {
240244 // or .text for old TS
241- let str = ( < ts . LiteralType > typ ) . value || ( typ as any ) . text ;
242- let num = parseFloat ( str ) ;
245+ let num = parseFloat ( str as string ) ;
243246 return isNaN ( num ) ? str : num ;
244247 } else if ( typ . flags & ts . TypeFlags . StringLiteral ) {
245- return ( < ts . LiteralType > typ ) . value || ( typ as any ) . text ;
248+ return str ;
246249 } else if ( typ . flags & ts . TypeFlags . NumberLiteral ) {
247- return parseFloat ( ( < ts . LiteralType > typ ) . value || ( typ as any ) . text ) ;
250+ return parseFloat ( str as string ) ;
248251 } else if ( typ . flags & ts . TypeFlags . BooleanLiteral ) {
249252 return ( typ as any ) . intrinsicName === "true" ;
250253 }
You can’t perform that action at this time.
0 commit comments