@@ -218,7 +218,7 @@ export class InterfaceType {
218218 this . abstract = abstract ;
219219 }
220220
221- toAstTypesString ( reflectionInfo : boolean ) : string {
221+ toAstTypesString ( reflectionInfo : boolean , optionalProperties ?: boolean ) : string {
222222 const interfaceSuperTypes = this . interfaceSuperTypes . map ( e => e . name ) ;
223223 const superTypes = interfaceSuperTypes . length > 0 ? distinctAndSorted ( [ ...interfaceSuperTypes ] ) : [ 'AstNode' ] ;
224224 const interfaceNode = expandToNode `
@@ -233,7 +233,7 @@ export class InterfaceType {
233233 body . append ( `readonly $type: ${ distinctAndSorted ( [ ...this . typeNames ] ) . map ( e => `'${ e } '` ) . join ( ' | ' ) } ;` ) . appendNewLine ( ) ;
234234 }
235235 body . append (
236- pushProperties ( this . properties , 'AstType' )
236+ pushProperties ( this . properties , 'AstType' , optionalProperties )
237237 ) ;
238238 } ) ;
239239 interfaceNode . append ( '}' ) . appendNewLine ( ) ;
@@ -253,7 +253,7 @@ export class InterfaceType {
253253 return toString (
254254 expandToNode `
255255 interface ${ name } ${ superTypes . length > 0 ? ` extends ${ superTypes } ` : '' } {
256- ${ pushProperties ( this . properties , 'DeclaredType' , reservedWords ) }
256+ ${ pushProperties ( this . properties , 'DeclaredType' , undefined , reservedWords ) }
257257 }
258258 ` . appendNewLine ( )
259259 ) ;
@@ -408,12 +408,13 @@ function typeParenthesis(type: PropertyType, name: string): string {
408408function pushProperties (
409409 properties : Property [ ] ,
410410 mode : 'AstType' | 'DeclaredType' ,
411+ optionalProperties ?: boolean ,
411412 reserved = new Set < string > ( )
412413) : Generated {
413414
414415 function propertyToString ( property : Property ) : string {
415416 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 ) ;
417418 const propType = propertyTypeToString ( property . type , mode ) ;
418419 return `${ name } ${ optional ? '?' : '' } : ${ propType } ;` ;
419420 }
0 commit comments