@@ -218,7 +218,7 @@ export class InterfaceType {
218
218
this . abstract = abstract ;
219
219
}
220
220
221
- toAstTypesString ( reflectionInfo : boolean ) : string {
221
+ toAstTypesString ( reflectionInfo : boolean , optionalProperties ?: boolean ) : string {
222
222
const interfaceSuperTypes = this . interfaceSuperTypes . map ( e => e . name ) ;
223
223
const superTypes = interfaceSuperTypes . length > 0 ? distinctAndSorted ( [ ...interfaceSuperTypes ] ) : [ 'AstNode' ] ;
224
224
const interfaceNode = expandToNode `
@@ -233,7 +233,7 @@ export class InterfaceType {
233
233
body . append ( `readonly $type: ${ distinctAndSorted ( [ ...this . typeNames ] ) . map ( e => `'${ e } '` ) . join ( ' | ' ) } ;` ) . appendNewLine ( ) ;
234
234
}
235
235
body . append (
236
- pushProperties ( this . properties , 'AstType' )
236
+ pushProperties ( this . properties , 'AstType' , optionalProperties )
237
237
) ;
238
238
} ) ;
239
239
interfaceNode . append ( '}' ) . appendNewLine ( ) ;
@@ -253,7 +253,7 @@ export class InterfaceType {
253
253
return toString (
254
254
expandToNode `
255
255
interface ${ name } ${ superTypes . length > 0 ? ` extends ${ superTypes } ` : '' } {
256
- ${ pushProperties ( this . properties , 'DeclaredType' , reservedWords ) }
256
+ ${ pushProperties ( this . properties , 'DeclaredType' , undefined , reservedWords ) }
257
257
}
258
258
` . appendNewLine ( )
259
259
) ;
@@ -408,12 +408,13 @@ function typeParenthesis(type: PropertyType, name: string): string {
408
408
function pushProperties (
409
409
properties : Property [ ] ,
410
410
mode : 'AstType' | 'DeclaredType' ,
411
+ optionalProperties ?: boolean ,
411
412
reserved = new Set < string > ( )
412
413
) : Generated {
413
414
414
415
function propertyToString ( property : Property ) : string {
415
416
const name = mode === 'AstType' ? property . name : escapeReservedWords ( property . name , reserved ) ;
416
- const optional = property . optional && ! isMandatoryPropertyType ( property . type ) ;
417
+ const optional = ! isMandatoryPropertyType ( property . type ) && ( property . optional || optionalProperties ) ;
417
418
const propType = propertyTypeToString ( property . type , mode ) ;
418
419
return `${ name } ${ optional ? '?' : '' } : ${ propType } ;` ;
419
420
}
0 commit comments