improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.36k stars 173 forks source link

proto3 - required / optional fields #287

Open AmitM30 opened 3 years ago

AmitM30 commented 3 years ago

Versions of relevant software used 0.15.0

What happened I am using proto3, and after generating the typescript schema, only some fields are marked as optional. While, afaik, everything should be optional by default.

What you expected to happen

In the following definition:

syntax = "proto3";

message Location {
  string title = 1;
  string description = 2;
  Link link = 3;
}

link is marked as optional, rest required. Not sure why.

How to reproduce it (as minimally and precisely as possible):

we could use the above definition and reproduce this.

link.proto

syntax = "proto3";

message Link {
  string key = 1;
  string title = 2;
  string url = 3;
}

Full logs to relevant components

Anything else we need to know

davidslaby commented 2 years ago

@AmitM30 Have you solved this issue somehow? :) Thanks in advance.

AmitM30 commented 2 years ago

@AmitM30 Have you solved this issue somehow? :) Thanks in advance.

@davidslaby No. I am living with it.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kimroen commented 2 years ago

I came here to find out which arguments we need to pass to fix this behavior as well - most of the types generated from our protos say the fields are there when they could be missing.

I would expect all of these to have | undefined added to the end of their types. Making this change now would probably be quite the breaking change, but an option and then gradual move could work?