Skip to content

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

@D4nte

Description

@D4nte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions