Skip to content

Commit c306d19

Browse files
committed
Added 'undefined' besides 'null' as a valid value of an optional field, fixes #826
1 parent c5518c3 commit c306d19

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

cli/targets/static.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function buildType(ref, type) {
391391
push("");
392392
var jsType = toJsType(field);
393393
if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type)
394-
jsType = "(" + jsType + "|null)";
394+
jsType = "(" + jsType + "|null|undefined)";
395395
pushComment([
396396
field.comment || type.name + " " + field.name + ".",
397397
"@member {" + jsType + "}" + escapeName(field.name),

tests/data/package.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Package {
2828
public description: string;
2929
public author: string;
3030
public license: string;
31-
public repository: (Package.IRepository|null);
31+
public repository?: (Package.IRepository|null);
3232
public bugs: string;
3333
public homepage: string;
3434
public keywords: string[];

tests/data/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $root.Package = (function() {
104104

105105
/**
106106
* Package repository.
107-
* @member {(Package.IRepository|null)}repository
107+
* @member {(Package.IRepository|null|undefined)}repository
108108
* @memberof Package
109109
* @instance
110110
*/

tests/data/test.d.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export namespace jspb {
121121
constructor(properties?: jspb.test.IOptionalFields);
122122
public aString: string;
123123
public aBool: boolean;
124-
public aNestedMessage: (jspb.test.OptionalFields.INested|null);
124+
public aNestedMessage?: (jspb.test.OptionalFields.INested|null);
125125
public aRepeatedMessage: jspb.test.OptionalFields.INested[];
126126
public aRepeatedString: string[];
127127
public static create(properties?: jspb.test.IOptionalFields): jspb.test.OptionalFields;
@@ -196,7 +196,7 @@ export namespace jspb {
196196
constructor(properties?: jspb.test.IComplex);
197197
public aString: string;
198198
public anOutOfOrderBool: boolean;
199-
public aNestedMessage: (jspb.test.Complex.INested|null);
199+
public aNestedMessage?: (jspb.test.Complex.INested|null);
200200
public aRepeatedMessage: jspb.test.Complex.INested[];
201201
public aRepeatedString: string[];
202202
public static create(properties?: jspb.test.IComplex): jspb.test.Complex;
@@ -382,7 +382,7 @@ export namespace jspb {
382382
class TestClone {
383383
constructor(properties?: jspb.test.ITestClone);
384384
public str: string;
385-
public simple1: (jspb.test.ISimple1|null);
385+
public simple1?: (jspb.test.ISimple1|null);
386386
public simple2: jspb.test.ISimple1[];
387387
public bytesField: Uint8Array;
388388
public unused: string;
@@ -428,10 +428,10 @@ export namespace jspb {
428428
constructor(properties?: jspb.test.ITestGroup);
429429
public repeatedGroup: jspb.test.TestGroup.IRepeatedGroup[];
430430
public requiredGroup: jspb.test.TestGroup.IRequiredGroup;
431-
public optionalGroup: (jspb.test.TestGroup.IOptionalGroup|null);
431+
public optionalGroup?: (jspb.test.TestGroup.IOptionalGroup|null);
432432
public id: string;
433433
public requiredSimple: jspb.test.ISimple2;
434-
public optionalSimple: (jspb.test.ISimple2|null);
434+
public optionalSimple?: (jspb.test.ISimple2|null);
435435
public static create(properties?: jspb.test.ITestGroup): jspb.test.TestGroup;
436436
public static encode(message: jspb.test.ITestGroup, writer?: $protobuf.Writer): $protobuf.Writer;
437437
public static encodeDelimited(message: jspb.test.ITestGroup, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -508,7 +508,7 @@ export namespace jspb {
508508

509509
class TestGroup1 {
510510
constructor(properties?: jspb.test.ITestGroup1);
511-
public group: (jspb.test.TestGroup.IRepeatedGroup|null);
511+
public group?: (jspb.test.TestGroup.IRepeatedGroup|null);
512512
public static create(properties?: jspb.test.ITestGroup1): jspb.test.TestGroup1;
513513
public static encode(message: jspb.test.ITestGroup1, writer?: $protobuf.Writer): $protobuf.Writer;
514514
public static encodeDelimited(message: jspb.test.ITestGroup1, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -572,7 +572,7 @@ export namespace jspb {
572572
constructor(properties?: jspb.test.ITestMessageWithOneof);
573573
public pone: string;
574574
public pthree: string;
575-
public rone: (jspb.test.ITestMessageWithOneof|null);
575+
public rone?: (jspb.test.ITestMessageWithOneof|null);
576576
public rtwo: string;
577577
public normalField: boolean;
578578
public repeatedField: string[];
@@ -642,7 +642,7 @@ export namespace jspb {
642642
public mapInt32String: { [k: string]: string };
643643
public mapInt64String: { [k: string]: string };
644644
public mapBoolString: { [k: string]: string };
645-
public testMapFields: (jspb.test.ITestMapFieldsNoBinary|null);
645+
public testMapFields?: (jspb.test.ITestMapFieldsNoBinary|null);
646646
public mapStringTestmapfields: { [k: string]: jspb.test.ITestMapFieldsNoBinary };
647647
public static create(properties?: jspb.test.ITestMapFieldsNoBinary): jspb.test.TestMapFieldsNoBinary;
648648
public static encode(message: jspb.test.ITestMapFieldsNoBinary, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -785,8 +785,8 @@ export namespace google {
785785
public enumType: google.protobuf.IEnumDescriptorProto[];
786786
public service: google.protobuf.IServiceDescriptorProto[];
787787
public extension: google.protobuf.IFieldDescriptorProto[];
788-
public options: (google.protobuf.IFileOptions|null);
789-
public sourceCodeInfo: (google.protobuf.ISourceCodeInfo|null);
788+
public options?: (google.protobuf.IFileOptions|null);
789+
public sourceCodeInfo?: (google.protobuf.ISourceCodeInfo|null);
790790
public syntax: string;
791791
public static create(properties?: google.protobuf.IFileDescriptorProto): google.protobuf.FileDescriptorProto;
792792
public static encode(message: google.protobuf.IFileDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -821,7 +821,7 @@ export namespace google {
821821
public enumType: google.protobuf.IEnumDescriptorProto[];
822822
public extensionRange: google.protobuf.DescriptorProto.IExtensionRange[];
823823
public oneofDecl: google.protobuf.IOneofDescriptorProto[];
824-
public options: (google.protobuf.IMessageOptions|null);
824+
public options?: (google.protobuf.IMessageOptions|null);
825825
public reservedRange: google.protobuf.DescriptorProto.IReservedRange[];
826826
public reservedName: string[];
827827
public static create(properties?: google.protobuf.IDescriptorProto): google.protobuf.DescriptorProto;
@@ -902,7 +902,7 @@ export namespace google {
902902
public defaultValue: string;
903903
public oneofIndex: number;
904904
public jsonName: string;
905-
public options: (google.protobuf.IFieldOptions|null);
905+
public options?: (google.protobuf.IFieldOptions|null);
906906
public static create(properties?: google.protobuf.IFieldDescriptorProto): google.protobuf.FieldDescriptorProto;
907907
public static encode(message: google.protobuf.IFieldDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
908908
public static encodeDelimited(message: google.protobuf.IFieldDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -952,7 +952,7 @@ export namespace google {
952952
class OneofDescriptorProto {
953953
constructor(properties?: google.protobuf.IOneofDescriptorProto);
954954
public name: string;
955-
public options: (google.protobuf.IOneofOptions|null);
955+
public options?: (google.protobuf.IOneofOptions|null);
956956
public static create(properties?: google.protobuf.IOneofDescriptorProto): google.protobuf.OneofDescriptorProto;
957957
public static encode(message: google.protobuf.IOneofDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
958958
public static encodeDelimited(message: google.protobuf.IOneofDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -974,7 +974,7 @@ export namespace google {
974974
constructor(properties?: google.protobuf.IEnumDescriptorProto);
975975
public name: string;
976976
public value: google.protobuf.IEnumValueDescriptorProto[];
977-
public options: (google.protobuf.IEnumOptions|null);
977+
public options?: (google.protobuf.IEnumOptions|null);
978978
public static create(properties?: google.protobuf.IEnumDescriptorProto): google.protobuf.EnumDescriptorProto;
979979
public static encode(message: google.protobuf.IEnumDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
980980
public static encodeDelimited(message: google.protobuf.IEnumDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -996,7 +996,7 @@ export namespace google {
996996
constructor(properties?: google.protobuf.IEnumValueDescriptorProto);
997997
public name: string;
998998
public number: number;
999-
public options: (google.protobuf.IEnumValueOptions|null);
999+
public options?: (google.protobuf.IEnumValueOptions|null);
10001000
public static create(properties?: google.protobuf.IEnumValueDescriptorProto): google.protobuf.EnumValueDescriptorProto;
10011001
public static encode(message: google.protobuf.IEnumValueDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
10021002
public static encodeDelimited(message: google.protobuf.IEnumValueDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -1018,7 +1018,7 @@ export namespace google {
10181018
constructor(properties?: google.protobuf.IServiceDescriptorProto);
10191019
public name: string;
10201020
public method: google.protobuf.IMethodDescriptorProto[];
1021-
public options: (google.protobuf.IServiceOptions|null);
1021+
public options?: (google.protobuf.IServiceOptions|null);
10221022
public static create(properties?: google.protobuf.IServiceDescriptorProto): google.protobuf.ServiceDescriptorProto;
10231023
public static encode(message: google.protobuf.IServiceDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
10241024
public static encodeDelimited(message: google.protobuf.IServiceDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
@@ -1044,7 +1044,7 @@ export namespace google {
10441044
public name: string;
10451045
public inputType: string;
10461046
public outputType: string;
1047-
public options: (google.protobuf.IMethodOptions|null);
1047+
public options?: (google.protobuf.IMethodOptions|null);
10481048
public clientStreaming: boolean;
10491049
public serverStreaming: boolean;
10501050
public static create(properties?: google.protobuf.IMethodDescriptorProto): google.protobuf.MethodDescriptorProto;

tests/data/test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ $root.jspb = (function() {
11711171

11721172
/**
11731173
* OptionalFields aNestedMessage.
1174-
* @member {(jspb.test.OptionalFields.INested|null)}aNestedMessage
1174+
* @member {(jspb.test.OptionalFields.INested|null|undefined)}aNestedMessage
11751175
* @memberof jspb.test.OptionalFields
11761176
* @instance
11771177
*/
@@ -1688,15 +1688,15 @@ $root.jspb = (function() {
16881688

16891689
/**
16901690
* HasExtensions .jspb.test.IsExtension.extField.
1691-
* @member {(jspb.test.IIsExtension|null)}.jspb.test.IsExtension.extField
1691+
* @member {(jspb.test.IIsExtension|null|undefined)}.jspb.test.IsExtension.extField
16921692
* @memberof jspb.test.HasExtensions
16931693
* @instance
16941694
*/
16951695
HasExtensions.prototype[".jspb.test.IsExtension.extField"] = null;
16961696

16971697
/**
16981698
* HasExtensions .jspb.test.IndirectExtension.simple.
1699-
* @member {(jspb.test.ISimple1|null)}.jspb.test.IndirectExtension.simple
1699+
* @member {(jspb.test.ISimple1|null|undefined)}.jspb.test.IndirectExtension.simple
17001700
* @memberof jspb.test.HasExtensions
17011701
* @instance
17021702
*/
@@ -1728,7 +1728,7 @@ $root.jspb = (function() {
17281728

17291729
/**
17301730
* HasExtensions .jspb.test.simple1.
1731-
* @member {(jspb.test.ISimple1|null)}.jspb.test.simple1
1731+
* @member {(jspb.test.ISimple1|null|undefined)}.jspb.test.simple1
17321732
* @memberof jspb.test.HasExtensions
17331733
* @instance
17341734
*/
@@ -2093,7 +2093,7 @@ $root.jspb = (function() {
20932093

20942094
/**
20952095
* Complex aNestedMessage.
2096-
* @member {(jspb.test.Complex.INested|null)}aNestedMessage
2096+
* @member {(jspb.test.Complex.INested|null|undefined)}aNestedMessage
20972097
* @memberof jspb.test.Complex
20982098
* @instance
20992099
*/
@@ -4009,7 +4009,7 @@ $root.jspb = (function() {
40094009

40104010
/**
40114011
* TestClone simple1.
4012-
* @member {(jspb.test.ISimple1|null)}simple1
4012+
* @member {(jspb.test.ISimple1|null|undefined)}simple1
40134013
* @memberof jspb.test.TestClone
40144014
* @instance
40154015
*/
@@ -4041,7 +4041,7 @@ $root.jspb = (function() {
40414041

40424042
/**
40434043
* TestClone .jspb.test.CloneExtension.extField.
4044-
* @member {(jspb.test.ICloneExtension|null)}.jspb.test.CloneExtension.extField
4044+
* @member {(jspb.test.ICloneExtension|null|undefined)}.jspb.test.CloneExtension.extField
40454045
* @memberof jspb.test.TestClone
40464046
* @instance
40474047
*/
@@ -4535,7 +4535,7 @@ $root.jspb = (function() {
45354535

45364536
/**
45374537
* TestGroup optionalGroup.
4538-
* @member {(jspb.test.TestGroup.IOptionalGroup|null)}optionalGroup
4538+
* @member {(jspb.test.TestGroup.IOptionalGroup|null|undefined)}optionalGroup
45394539
* @memberof jspb.test.TestGroup
45404540
* @instance
45414541
*/
@@ -4559,7 +4559,7 @@ $root.jspb = (function() {
45594559

45604560
/**
45614561
* TestGroup optionalSimple.
4562-
* @member {(jspb.test.ISimple2|null)}optionalSimple
4562+
* @member {(jspb.test.ISimple2|null|undefined)}optionalSimple
45634563
* @memberof jspb.test.TestGroup
45644564
* @instance
45654565
*/
@@ -5458,7 +5458,7 @@ $root.jspb = (function() {
54585458

54595459
/**
54605460
* TestGroup1 group.
5461-
* @member {(jspb.test.TestGroup.IRepeatedGroup|null)}group
5461+
* @member {(jspb.test.TestGroup.IRepeatedGroup|null|undefined)}group
54625462
* @memberof jspb.test.TestGroup1
54635463
* @instance
54645464
*/
@@ -6043,7 +6043,7 @@ $root.jspb = (function() {
60436043

60446044
/**
60456045
* TestMessageWithOneof rone.
6046-
* @member {(jspb.test.ITestMessageWithOneof|null)}rone
6046+
* @member {(jspb.test.ITestMessageWithOneof|null|undefined)}rone
60476047
* @memberof jspb.test.TestMessageWithOneof
60486048
* @instance
60496049
*/
@@ -6824,7 +6824,7 @@ $root.jspb = (function() {
68246824

68256825
/**
68266826
* TestMapFieldsNoBinary testMapFields.
6827-
* @member {(jspb.test.ITestMapFieldsNoBinary|null)}testMapFields
6827+
* @member {(jspb.test.ITestMapFieldsNoBinary|null|undefined)}testMapFields
68286828
* @memberof jspb.test.TestMapFieldsNoBinary
68296829
* @instance
68306830
*/
@@ -8456,15 +8456,15 @@ $root.google = (function() {
84568456

84578457
/**
84588458
* FileDescriptorProto options.
8459-
* @member {(google.protobuf.IFileOptions|null)}options
8459+
* @member {(google.protobuf.IFileOptions|null|undefined)}options
84608460
* @memberof google.protobuf.FileDescriptorProto
84618461
* @instance
84628462
*/
84638463
FileDescriptorProto.prototype.options = null;
84648464

84658465
/**
84668466
* FileDescriptorProto sourceCodeInfo.
8467-
* @member {(google.protobuf.ISourceCodeInfo|null)}sourceCodeInfo
8467+
* @member {(google.protobuf.ISourceCodeInfo|null|undefined)}sourceCodeInfo
84688468
* @memberof google.protobuf.FileDescriptorProto
84698469
* @instance
84708470
*/
@@ -9022,7 +9022,7 @@ $root.google = (function() {
90229022

90239023
/**
90249024
* DescriptorProto options.
9025-
* @member {(google.protobuf.IMessageOptions|null)}options
9025+
* @member {(google.protobuf.IMessageOptions|null|undefined)}options
90269026
* @memberof google.protobuf.DescriptorProto
90279027
* @instance
90289028
*/
@@ -10003,7 +10003,7 @@ $root.google = (function() {
1000310003

1000410004
/**
1000510005
* FieldDescriptorProto options.
10006-
* @member {(google.protobuf.IFieldOptions|null)}options
10006+
* @member {(google.protobuf.IFieldOptions|null|undefined)}options
1000710007
* @memberof google.protobuf.FieldDescriptorProto
1000810008
* @instance
1000910009
*/
@@ -10492,7 +10492,7 @@ $root.google = (function() {
1049210492

1049310493
/**
1049410494
* OneofDescriptorProto options.
10495-
* @member {(google.protobuf.IOneofOptions|null)}options
10495+
* @member {(google.protobuf.IOneofOptions|null|undefined)}options
1049610496
* @memberof google.protobuf.OneofDescriptorProto
1049710497
* @instance
1049810498
*/
@@ -10716,7 +10716,7 @@ $root.google = (function() {
1071610716

1071710717
/**
1071810718
* EnumDescriptorProto options.
10719-
* @member {(google.protobuf.IEnumOptions|null)}options
10719+
* @member {(google.protobuf.IEnumOptions|null|undefined)}options
1072010720
* @memberof google.protobuf.EnumDescriptorProto
1072110721
* @instance
1072210722
*/
@@ -10973,7 +10973,7 @@ $root.google = (function() {
1097310973

1097410974
/**
1097510975
* EnumValueDescriptorProto options.
10976-
* @member {(google.protobuf.IEnumValueOptions|null)}options
10976+
* @member {(google.protobuf.IEnumValueOptions|null|undefined)}options
1097710977
* @memberof google.protobuf.EnumValueDescriptorProto
1097810978
* @instance
1097910979
*/
@@ -11210,7 +11210,7 @@ $root.google = (function() {
1121011210

1121111211
/**
1121211212
* ServiceDescriptorProto options.
11213-
* @member {(google.protobuf.IServiceOptions|null)}options
11213+
* @member {(google.protobuf.IServiceOptions|null|undefined)}options
1121411214
* @memberof google.protobuf.ServiceDescriptorProto
1121511215
* @instance
1121611216
*/
@@ -11478,7 +11478,7 @@ $root.google = (function() {
1147811478

1147911479
/**
1148011480
* MethodDescriptorProto options.
11481-
* @member {(google.protobuf.IMethodOptions|null)}options
11481+
* @member {(google.protobuf.IMethodOptions|null|undefined)}options
1148211482
* @memberof google.protobuf.MethodDescriptorProto
1148311483
* @instance
1148411484
*/

0 commit comments

Comments
 (0)