bufbuild / protobuf-es

Protocol Buffers for ECMAScript. The only JavaScript Protobuf library that is fully-compliant with Protobuf conformance tests.
Apache License 2.0
1.16k stars 69 forks source link

Feature request: Allow prefixing generated type names #1017

Open csimmons0 opened 3 days ago

csimmons0 commented 3 days ago

It would be great if we could simply add a line to buf.gen.yaml that made the generator add a prefix to the generated types' names. For example, I would just say typesPrefix: "Pb" in the yaml file, and then for this proto enum:

enum Foo {
  ...
}

the generated TS code would be

export enum PbFoo {
  ...
}

Same for message types and their TS classes. The motivation for this request is to avoid name collisions between generated TS types and manually-written types that correspond to them. Without this feature I have to manually alias names when I import them, as in

import {Foo as PbFoo} from ...