ipfs / protons

Protocol Buffers for Node.js and the browser without eval
Other
32 stars 23 forks source link

Code generated for singular message fields does not allow for absent field #42

Closed D4nte closed 1 year ago

D4nte commented 2 years ago

Expected

As per proto3's language guide:

Message fields can be one of the following:

  • singular: a well-formed message can have zero or one of this field (but not more than one). And this is the default field rule for proto3 syntax.

Hence, I would expect the TypeScript code to allow singular fields to be undefined

syntax = "proto3";

message Message {
  bytes payload = 1;
}

should generate

export interface Message {
  payload?: Uint8Array
}

Actual

syntax = "proto3";

message Message {
  bytes payload = 1;
}

generates

export interface Message {
  payload: Uint8Array
}

Note

When using the optional keyword, I can get the desired effect:

 message Message {
  optional bytes payload = 1;
}
export interface Message {
  payload?: Uint8Array
}

However, optional is not part of the proto3 syntax.

D4nte commented 2 years ago

@achingbrain Do you have any opinion on the matter? I am happy to submit a PR but would like to know what direction is preferred first :) same for #43.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version protons-v7.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: