File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ Translates between file formats and generates static code.
68
68
--force-long Enforces the use of 'Long' for s-/u-/int64 and s-/fixed64 fields.
69
69
--force-number Enforces the use of 'number' for s-/u-/int64 and s-/fixed64 fields.
70
70
--force-message Enforces the use of message instances instead of plain objects.
71
- --pb3-optional Make type declarations respect optional fields for PB3.
71
+ --null-defaults Default value for optional fields is null instead of zero value.
72
+ --pb3-optional Make type declarations respect optional fields for PB3.
72
73
73
74
usage: pbjs [options] file1.proto file2.json ... (or pipe) other | pbjs [options] -
74
75
```
Original file line number Diff line number Diff line change @@ -356,7 +356,7 @@ function toJsType(field) {
356
356
357
357
function handleOptionalFields ( jsType , field ) {
358
358
359
- if ( field . optional && ! field . map && ! field . repeated && ( field . resolvedType instanceof Type || config [ "null-defaults" ] ) || field . partOf )
359
+ if ( field . optional && ! field . map && ! field . repeated && field . resolvedType instanceof Type || field . partOf )
360
360
return jsType + "|null|undefined" ;
361
361
else
362
362
return jsType
@@ -410,8 +410,16 @@ function buildType(ref, type) {
410
410
if ( config . comments ) {
411
411
push ( "" ) ;
412
412
var jsType = toJsType ( field ) ;
413
- // No need to check config.tsOptional for member types, this logic has not changed
414
- jsType = handleOptionalFields ( jsType , field ) ;
413
+
414
+ // Hide the fix for PB3 optional fields behind a config flag, it is an API change in generated output
415
+ if ( config . pb3Optional ) {
416
+ jsType = handleOptionalFields ( jsType , field ) ;
417
+ }
418
+ else {
419
+ if ( field . optional && ! field . map && ! field . repeated && ( field . resolvedType instanceof Type || config [ "null-defaults" ] ) || field . partOf )
420
+ jsType = jsType + "|null|undefined" ;
421
+ }
422
+
415
423
pushComment ( [
416
424
field . comment || type . name + " " + field . name + "." ,
417
425
"@member {" + jsType + "} " + field . name ,
You can’t perform that action at this time.
0 commit comments