@@ -311,9 +311,15 @@ function buildFunction(type, functionName, gen, scope) {
311
311
push ( "};" ) ;
312
312
}
313
313
314
- function toJsType ( field ) {
314
+ function toJsType ( field , parentIsInterface ) {
315
315
var type ;
316
316
317
+ // With null semantics, interfaces are composed from interfaces and messages from messages
318
+ // Without null semantics, child types depend on the --force-message flag
319
+ var asInterface = config [ "null-semantics" ]
320
+ ? parentIsInterface && ! ( field . resolvedType instanceof protobuf . Enum )
321
+ : ! ( field . resolvedType instanceof protobuf . Enum || config . forceMessage ) ;
322
+
317
323
switch ( field . type ) {
318
324
case "double" :
319
325
case "float" :
@@ -342,7 +348,7 @@ function toJsType(field) {
342
348
break ;
343
349
default :
344
350
if ( field . resolve ( ) . resolvedType )
345
- type = exportName ( field . resolvedType , ! ( field . resolvedType instanceof protobuf . Enum || config . forceMessage ) ) ;
351
+ type = exportName ( field . resolvedType , asInterface ) ;
346
352
else
347
353
type = "*" ; // should not happen
348
354
break ;
@@ -407,7 +413,7 @@ function buildType(ref, type) {
407
413
type . fieldsArray . forEach ( function ( field ) {
408
414
var prop = util . safeProp ( field . name ) ; // either .name or ["name"]
409
415
prop = prop . substring ( 1 , prop . charAt ( 0 ) === "[" ? prop . length - 1 : prop . length ) ;
410
- var jsType = toJsType ( field ) ;
416
+ var jsType = toJsType ( field , /* parentIsInterface = */ true ) ;
411
417
var nullable = false ;
412
418
if ( config [ "null-semantics" ] ) {
413
419
// With semantic nulls, decide which fields are required for the current protobuf version
@@ -451,7 +457,7 @@ function buildType(ref, type) {
451
457
var prop = util . safeProp ( field . name ) ;
452
458
if ( config . comments ) {
453
459
push ( "" ) ;
454
- var jsType = toJsType ( field ) ;
460
+ var jsType = toJsType ( field , /* parentIsInterface = */ false ) ;
455
461
if ( config [ "null-semantics" ] ) {
456
462
// With semantic nulls, fields are nullable if they are explicitly optional or part of a one-of
457
463
// Maps, repeated values and fields with implicit defaults are never null after construction
0 commit comments