protobuf-es icon indicating copy to clipboard operation
protobuf-es copied to clipboard

Improve type representation for open enums

Open timostamm opened this issue 6 months ago • 0 comments

Protobuf has closed and open enums. A closed enum (proto2) only accepts declared values, while an open enum (proto3) also accepts other values. protoc-gen-es generates TypeScript enums, which are always closed since version 5.0.

This means that generated types do not match the semantics for open Protobuf enums. There is no indication that an enum field could contain a value that isn't one of the TypeScript enum values, and additional checks might even be flagged as unnecessary or incorrect by the compiler.

We should investigate how to improve the generated enum types or fields to properly reflect open enum semantics.

Context:

  • protobuf.dev on Enum behavior
  • https://github.com/bufbuild/protobuf-es/issues/1082
  • https://github.com/bufbuild/protobuf-es/issues/522
  • https://github.com/bufbuild/protobuf-es/issues/1139

timostamm avatar Aug 25 '25 14:08 timostamm