Skip to content

Commit ccd640e

Browse files
Do not require repeated or map fields in the object properties (i.e. for interface types)
1 parent 856af47 commit ccd640e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

cli/targets/static.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,10 @@ function buildType(ref, type) {
395395
var jsType = toJsType(field);
396396
var nullable = false;
397397

398-
// New behaviour - fields explicitly marked as optional and members of a one-of are nullable
399-
// Maps and repeated fields are not explicitly optional, they default to empty instances
398+
// New behaviour - respect explicit optional semantics in both proto2 and proto3
400399
if (config["force-optional"]) {
401-
if (isOptional(field, syntax) || field.partOf) {
402-
jsType = jsType + "|null|undefined";
400+
if (isOptional(field, syntax) || field.partOf || field.repeated || field.map) {
401+
jsType = jsType + "|null";
403402
nullable = true;
404403
}
405404
}
@@ -439,7 +438,7 @@ function buildType(ref, type) {
439438
var jsType = toJsType(field);
440439

441440
// New behaviour - fields explicitly marked as optional and members of a one-of are nullable
442-
// Maps and repeated fields are not explicitly optional, they default to empty instances
441+
// Maps and repeated fields are not nullable, they default to empty instances
443442
if (config["force-optional"]) {
444443
if (isOptional(field, syntax) || field.partOf)
445444
jsType = jsType + "|null|undefined";

0 commit comments

Comments
 (0)