@@ -354,6 +354,14 @@ function toJsType(field) {
354
354
return type ;
355
355
}
356
356
357
+ function handleOptionalFields ( jsType , field ) {
358
+
359
+ if ( field . optional && ! field . map && ! field . repeated && ( field . resolvedType instanceof Type || config [ "null-defaults" ] ) || field . partOf )
360
+ return jsType + "|null|undefined" ;
361
+ else
362
+ return jsType
363
+ }
364
+
357
365
function buildType ( ref , type ) {
358
366
359
367
if ( config . comments ) {
@@ -366,8 +374,7 @@ function buildType(ref, type) {
366
374
var prop = util . safeProp ( field . name ) ; // either .name or ["name"]
367
375
prop = prop . substring ( 1 , prop . charAt ( 0 ) === "[" ? prop . length - 1 : prop . length ) ;
368
376
var jsType = toJsType ( field ) ;
369
- if ( field . optional )
370
- jsType = jsType + "|null" ;
377
+ jsType = handleOptionalFields ( jsType , field ) ;
371
378
typeDef . push ( "@property {" + jsType + "} " + ( field . optional ? "[" + prop + "]" : prop ) + " " + ( field . comment || type . name + " " + field . name ) ) ;
372
379
} ) ;
373
380
push ( "" ) ;
@@ -394,8 +401,7 @@ function buildType(ref, type) {
394
401
if ( config . comments ) {
395
402
push ( "" ) ;
396
403
var jsType = toJsType ( field ) ;
397
- if ( field . optional && ! field . map && ! field . repeated && ( field . resolvedType instanceof Type || config [ "null-defaults" ] ) || field . partOf )
398
- jsType = jsType + "|null|undefined" ;
404
+ jsType = handleOptionalFields ( jsType , field ) ;
399
405
pushComment ( [
400
406
field . comment || type . name + " " + field . name + "." ,
401
407
"@member {" + jsType + "} " + field . name ,
0 commit comments