Skip to content

Commit

Permalink
remove null from optional field type union
Browse files Browse the repository at this point in the history
Messages with optional fields will now implement their corresponding
interfaces (IMessage)

fixes protobufjs#834
fixes protobufjs#837
  • Loading branch information
Alexendoo committed Jun 24, 2017
1 parent c43243b commit d15bbac
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function buildType(ref, type) {
push("");
var jsType = toJsType(field);
if (field.optional && !field.map && !field.repeated && field.resolvedType instanceof Type)
jsType = "(" + jsType + "|null|undefined)";
jsType = "(" + jsType + "|undefined)";
pushComment([
field.comment || type.name + " " + field.name + ".",
"@member {" + jsType + "}" + escapeName(field.name),
Expand Down
2 changes: 1 addition & 1 deletion tests/data/package.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Package {
public description: string;
public author: string;
public license: string;
public repository?: (Package.IRepository|null);
public repository?: Package.IRepository;
public bugs: string;
public homepage: string;
public keywords: string[];
Expand Down
2 changes: 1 addition & 1 deletion tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $root.Package = (function() {

/**
* Package repository.
* @member {(Package.IRepository|null|undefined)}repository
* @member {(Package.IRepository|undefined)}repository
* @memberof Package
* @instance
*/
Expand Down
34 changes: 17 additions & 17 deletions tests/data/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export namespace jspb {
constructor(properties?: jspb.test.IOptionalFields);
public aString: string;
public aBool: boolean;
public aNestedMessage?: (jspb.test.OptionalFields.INested|null);
public aNestedMessage?: jspb.test.OptionalFields.INested;
public aRepeatedMessage: jspb.test.OptionalFields.INested[];
public aRepeatedString: string[];
public static create(properties?: jspb.test.IOptionalFields): jspb.test.OptionalFields;
Expand Down Expand Up @@ -196,7 +196,7 @@ export namespace jspb {
constructor(properties?: jspb.test.IComplex);
public aString: string;
public anOutOfOrderBool: boolean;
public aNestedMessage?: (jspb.test.Complex.INested|null);
public aNestedMessage?: jspb.test.Complex.INested;
public aRepeatedMessage: jspb.test.Complex.INested[];
public aRepeatedString: string[];
public static create(properties?: jspb.test.IComplex): jspb.test.Complex;
Expand Down Expand Up @@ -382,7 +382,7 @@ export namespace jspb {
class TestClone {
constructor(properties?: jspb.test.ITestClone);
public str: string;
public simple1?: (jspb.test.ISimple1|null);
public simple1?: jspb.test.ISimple1;
public simple2: jspb.test.ISimple1[];
public bytesField: Uint8Array;
public unused: string;
Expand Down Expand Up @@ -428,10 +428,10 @@ export namespace jspb {
constructor(properties?: jspb.test.ITestGroup);
public repeatedGroup: jspb.test.TestGroup.IRepeatedGroup[];
public requiredGroup: jspb.test.TestGroup.IRequiredGroup;
public optionalGroup?: (jspb.test.TestGroup.IOptionalGroup|null);
public optionalGroup?: jspb.test.TestGroup.IOptionalGroup;
public id: string;
public requiredSimple: jspb.test.ISimple2;
public optionalSimple?: (jspb.test.ISimple2|null);
public optionalSimple?: jspb.test.ISimple2;
public static create(properties?: jspb.test.ITestGroup): jspb.test.TestGroup;
public static encode(message: jspb.test.ITestGroup, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: jspb.test.ITestGroup, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down Expand Up @@ -508,7 +508,7 @@ export namespace jspb {

class TestGroup1 {
constructor(properties?: jspb.test.ITestGroup1);
public group?: (jspb.test.TestGroup.IRepeatedGroup|null);
public group?: jspb.test.TestGroup.IRepeatedGroup;
public static create(properties?: jspb.test.ITestGroup1): jspb.test.TestGroup1;
public static encode(message: jspb.test.ITestGroup1, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: jspb.test.ITestGroup1, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down Expand Up @@ -572,7 +572,7 @@ export namespace jspb {
constructor(properties?: jspb.test.ITestMessageWithOneof);
public pone: string;
public pthree: string;
public rone?: (jspb.test.ITestMessageWithOneof|null);
public rone?: jspb.test.ITestMessageWithOneof;
public rtwo: string;
public normalField: boolean;
public repeatedField: string[];
Expand Down Expand Up @@ -642,7 +642,7 @@ export namespace jspb {
public mapInt32String: { [k: string]: string };
public mapInt64String: { [k: string]: string };
public mapBoolString: { [k: string]: string };
public testMapFields?: (jspb.test.ITestMapFieldsNoBinary|null);
public testMapFields?: jspb.test.ITestMapFieldsNoBinary;
public mapStringTestmapfields: { [k: string]: jspb.test.ITestMapFieldsNoBinary };
public static create(properties?: jspb.test.ITestMapFieldsNoBinary): jspb.test.TestMapFieldsNoBinary;
public static encode(message: jspb.test.ITestMapFieldsNoBinary, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down Expand Up @@ -785,8 +785,8 @@ export namespace google {
public enumType: google.protobuf.IEnumDescriptorProto[];
public service: google.protobuf.IServiceDescriptorProto[];
public extension: google.protobuf.IFieldDescriptorProto[];
public options?: (google.protobuf.IFileOptions|null);
public sourceCodeInfo?: (google.protobuf.ISourceCodeInfo|null);
public options?: google.protobuf.IFileOptions;
public sourceCodeInfo?: google.protobuf.ISourceCodeInfo;
public syntax: string;
public static create(properties?: google.protobuf.IFileDescriptorProto): google.protobuf.FileDescriptorProto;
public static encode(message: google.protobuf.IFileDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down Expand Up @@ -821,7 +821,7 @@ export namespace google {
public enumType: google.protobuf.IEnumDescriptorProto[];
public extensionRange: google.protobuf.DescriptorProto.IExtensionRange[];
public oneofDecl: google.protobuf.IOneofDescriptorProto[];
public options?: (google.protobuf.IMessageOptions|null);
public options?: google.protobuf.IMessageOptions;
public reservedRange: google.protobuf.DescriptorProto.IReservedRange[];
public reservedName: string[];
public static create(properties?: google.protobuf.IDescriptorProto): google.protobuf.DescriptorProto;
Expand Down Expand Up @@ -902,7 +902,7 @@ export namespace google {
public defaultValue: string;
public oneofIndex: number;
public jsonName: string;
public options?: (google.protobuf.IFieldOptions|null);
public options?: google.protobuf.IFieldOptions;
public static create(properties?: google.protobuf.IFieldDescriptorProto): google.protobuf.FieldDescriptorProto;
public static encode(message: google.protobuf.IFieldDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: google.protobuf.IFieldDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand Down Expand Up @@ -952,7 +952,7 @@ export namespace google {
class OneofDescriptorProto {
constructor(properties?: google.protobuf.IOneofDescriptorProto);
public name: string;
public options?: (google.protobuf.IOneofOptions|null);
public options?: google.protobuf.IOneofOptions;
public static create(properties?: google.protobuf.IOneofDescriptorProto): google.protobuf.OneofDescriptorProto;
public static encode(message: google.protobuf.IOneofDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: google.protobuf.IOneofDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand All @@ -974,7 +974,7 @@ export namespace google {
constructor(properties?: google.protobuf.IEnumDescriptorProto);
public name: string;
public value: google.protobuf.IEnumValueDescriptorProto[];
public options?: (google.protobuf.IEnumOptions|null);
public options?: google.protobuf.IEnumOptions;
public static create(properties?: google.protobuf.IEnumDescriptorProto): google.protobuf.EnumDescriptorProto;
public static encode(message: google.protobuf.IEnumDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: google.protobuf.IEnumDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand All @@ -996,7 +996,7 @@ export namespace google {
constructor(properties?: google.protobuf.IEnumValueDescriptorProto);
public name: string;
public number: number;
public options?: (google.protobuf.IEnumValueOptions|null);
public options?: google.protobuf.IEnumValueOptions;
public static create(properties?: google.protobuf.IEnumValueDescriptorProto): google.protobuf.EnumValueDescriptorProto;
public static encode(message: google.protobuf.IEnumValueDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: google.protobuf.IEnumValueDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand All @@ -1018,7 +1018,7 @@ export namespace google {
constructor(properties?: google.protobuf.IServiceDescriptorProto);
public name: string;
public method: google.protobuf.IMethodDescriptorProto[];
public options?: (google.protobuf.IServiceOptions|null);
public options?: google.protobuf.IServiceOptions;
public static create(properties?: google.protobuf.IServiceDescriptorProto): google.protobuf.ServiceDescriptorProto;
public static encode(message: google.protobuf.IServiceDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
public static encodeDelimited(message: google.protobuf.IServiceDescriptorProto, writer?: $protobuf.Writer): $protobuf.Writer;
Expand All @@ -1044,7 +1044,7 @@ export namespace google {
public name: string;
public inputType: string;
public outputType: string;
public options?: (google.protobuf.IMethodOptions|null);
public options?: google.protobuf.IMethodOptions;
public clientStreaming: boolean;
public serverStreaming: boolean;
public static create(properties?: google.protobuf.IMethodDescriptorProto): google.protobuf.MethodDescriptorProto;
Expand Down
42 changes: 21 additions & 21 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ $root.jspb = (function() {

/**
* OptionalFields aNestedMessage.
* @member {(jspb.test.OptionalFields.INested|null|undefined)}aNestedMessage
* @member {(jspb.test.OptionalFields.INested|undefined)}aNestedMessage
* @memberof jspb.test.OptionalFields
* @instance
*/
Expand Down Expand Up @@ -1688,15 +1688,15 @@ $root.jspb = (function() {

/**
* HasExtensions .jspb.test.IsExtension.extField.
* @member {(jspb.test.IIsExtension|null|undefined)}.jspb.test.IsExtension.extField
* @member {(jspb.test.IIsExtension|undefined)}.jspb.test.IsExtension.extField
* @memberof jspb.test.HasExtensions
* @instance
*/
HasExtensions.prototype[".jspb.test.IsExtension.extField"] = null;

/**
* HasExtensions .jspb.test.IndirectExtension.simple.
* @member {(jspb.test.ISimple1|null|undefined)}.jspb.test.IndirectExtension.simple
* @member {(jspb.test.ISimple1|undefined)}.jspb.test.IndirectExtension.simple
* @memberof jspb.test.HasExtensions
* @instance
*/
Expand Down Expand Up @@ -1728,7 +1728,7 @@ $root.jspb = (function() {

/**
* HasExtensions .jspb.test.simple1.
* @member {(jspb.test.ISimple1|null|undefined)}.jspb.test.simple1
* @member {(jspb.test.ISimple1|undefined)}.jspb.test.simple1
* @memberof jspb.test.HasExtensions
* @instance
*/
Expand Down Expand Up @@ -2093,7 +2093,7 @@ $root.jspb = (function() {

/**
* Complex aNestedMessage.
* @member {(jspb.test.Complex.INested|null|undefined)}aNestedMessage
* @member {(jspb.test.Complex.INested|undefined)}aNestedMessage
* @memberof jspb.test.Complex
* @instance
*/
Expand Down Expand Up @@ -4009,7 +4009,7 @@ $root.jspb = (function() {

/**
* TestClone simple1.
* @member {(jspb.test.ISimple1|null|undefined)}simple1
* @member {(jspb.test.ISimple1|undefined)}simple1
* @memberof jspb.test.TestClone
* @instance
*/
Expand Down Expand Up @@ -4041,7 +4041,7 @@ $root.jspb = (function() {

/**
* TestClone .jspb.test.CloneExtension.extField.
* @member {(jspb.test.ICloneExtension|null|undefined)}.jspb.test.CloneExtension.extField
* @member {(jspb.test.ICloneExtension|undefined)}.jspb.test.CloneExtension.extField
* @memberof jspb.test.TestClone
* @instance
*/
Expand Down Expand Up @@ -4535,7 +4535,7 @@ $root.jspb = (function() {

/**
* TestGroup optionalGroup.
* @member {(jspb.test.TestGroup.IOptionalGroup|null|undefined)}optionalGroup
* @member {(jspb.test.TestGroup.IOptionalGroup|undefined)}optionalGroup
* @memberof jspb.test.TestGroup
* @instance
*/
Expand All @@ -4559,7 +4559,7 @@ $root.jspb = (function() {

/**
* TestGroup optionalSimple.
* @member {(jspb.test.ISimple2|null|undefined)}optionalSimple
* @member {(jspb.test.ISimple2|undefined)}optionalSimple
* @memberof jspb.test.TestGroup
* @instance
*/
Expand Down Expand Up @@ -5458,7 +5458,7 @@ $root.jspb = (function() {

/**
* TestGroup1 group.
* @member {(jspb.test.TestGroup.IRepeatedGroup|null|undefined)}group
* @member {(jspb.test.TestGroup.IRepeatedGroup|undefined)}group
* @memberof jspb.test.TestGroup1
* @instance
*/
Expand Down Expand Up @@ -6043,7 +6043,7 @@ $root.jspb = (function() {

/**
* TestMessageWithOneof rone.
* @member {(jspb.test.ITestMessageWithOneof|null|undefined)}rone
* @member {(jspb.test.ITestMessageWithOneof|undefined)}rone
* @memberof jspb.test.TestMessageWithOneof
* @instance
*/
Expand Down Expand Up @@ -6824,7 +6824,7 @@ $root.jspb = (function() {

/**
* TestMapFieldsNoBinary testMapFields.
* @member {(jspb.test.ITestMapFieldsNoBinary|null|undefined)}testMapFields
* @member {(jspb.test.ITestMapFieldsNoBinary|undefined)}testMapFields
* @memberof jspb.test.TestMapFieldsNoBinary
* @instance
*/
Expand Down Expand Up @@ -8456,15 +8456,15 @@ $root.google = (function() {

/**
* FileDescriptorProto options.
* @member {(google.protobuf.IFileOptions|null|undefined)}options
* @member {(google.protobuf.IFileOptions|undefined)}options
* @memberof google.protobuf.FileDescriptorProto
* @instance
*/
FileDescriptorProto.prototype.options = null;

/**
* FileDescriptorProto sourceCodeInfo.
* @member {(google.protobuf.ISourceCodeInfo|null|undefined)}sourceCodeInfo
* @member {(google.protobuf.ISourceCodeInfo|undefined)}sourceCodeInfo
* @memberof google.protobuf.FileDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -9022,7 +9022,7 @@ $root.google = (function() {

/**
* DescriptorProto options.
* @member {(google.protobuf.IMessageOptions|null|undefined)}options
* @member {(google.protobuf.IMessageOptions|undefined)}options
* @memberof google.protobuf.DescriptorProto
* @instance
*/
Expand Down Expand Up @@ -10003,7 +10003,7 @@ $root.google = (function() {

/**
* FieldDescriptorProto options.
* @member {(google.protobuf.IFieldOptions|null|undefined)}options
* @member {(google.protobuf.IFieldOptions|undefined)}options
* @memberof google.protobuf.FieldDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -10492,7 +10492,7 @@ $root.google = (function() {

/**
* OneofDescriptorProto options.
* @member {(google.protobuf.IOneofOptions|null|undefined)}options
* @member {(google.protobuf.IOneofOptions|undefined)}options
* @memberof google.protobuf.OneofDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -10716,7 +10716,7 @@ $root.google = (function() {

/**
* EnumDescriptorProto options.
* @member {(google.protobuf.IEnumOptions|null|undefined)}options
* @member {(google.protobuf.IEnumOptions|undefined)}options
* @memberof google.protobuf.EnumDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -10973,7 +10973,7 @@ $root.google = (function() {

/**
* EnumValueDescriptorProto options.
* @member {(google.protobuf.IEnumValueOptions|null|undefined)}options
* @member {(google.protobuf.IEnumValueOptions|undefined)}options
* @memberof google.protobuf.EnumValueDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -11210,7 +11210,7 @@ $root.google = (function() {

/**
* ServiceDescriptorProto options.
* @member {(google.protobuf.IServiceOptions|null|undefined)}options
* @member {(google.protobuf.IServiceOptions|undefined)}options
* @memberof google.protobuf.ServiceDescriptorProto
* @instance
*/
Expand Down Expand Up @@ -11478,7 +11478,7 @@ $root.google = (function() {

/**
* MethodDescriptorProto options.
* @member {(google.protobuf.IMethodOptions|null|undefined)}options
* @member {(google.protobuf.IMethodOptions|undefined)}options
* @memberof google.protobuf.MethodDescriptorProto
* @instance
*/
Expand Down

0 comments on commit d15bbac

Please sign in to comment.