File tree 5 files changed +11
-6
lines changed
5 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
class MyObject {
2
- foo : "ok" | "fail" | "abort" ;
2
+ foo : "ok" | "fail" | "abort" | "" ;
3
3
bar : "ok" | "fail" | "abort" | string ;
4
4
}
Original file line number Diff line number Diff line change 6
6
},
7
7
"foo" : {
8
8
"enum" : [
9
+ " " ,
9
10
" abort" ,
10
11
" fail" ,
11
12
" ok"
Original file line number Diff line number Diff line change 1
- type result = "ok" | "fail" | "abort" ;
1
+ type result = "ok" | "fail" | "abort" | "" ;
2
2
3
3
class MyObject {
4
4
foo : result ;
Original file line number Diff line number Diff line change 3
3
"definitions" : {
4
4
"result" : {
5
5
"enum" : [
6
+ " " ,
6
7
" abort" ,
7
8
" fail" ,
8
9
" ok"
Original file line number Diff line number Diff line change @@ -236,15 +236,18 @@ export class JsonSchemaGenerator {
236
236
}
237
237
238
238
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
+ }
239
243
if ( typ . flags & ts . TypeFlags . EnumLiteral ) {
240
244
// 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 ) ;
243
246
return isNaN ( num ) ? str : num ;
244
247
} else if ( typ . flags & ts . TypeFlags . StringLiteral ) {
245
- return ( < ts . LiteralType > typ ) . value || ( typ as any ) . text ;
248
+ return str ;
246
249
} else if ( typ . flags & ts . TypeFlags . NumberLiteral ) {
247
- return parseFloat ( ( < ts . LiteralType > typ ) . value || ( typ as any ) . text ) ;
250
+ return parseFloat ( str as string ) ;
248
251
} else if ( typ . flags & ts . TypeFlags . BooleanLiteral ) {
249
252
return ( typ as any ) . intrinsicName === "true" ;
250
253
}
You can’t perform that action at this time.
0 commit comments