Skip to content

RFC: Problems which we already solved by taking modern approaches and what should we do next #39

@thesayyn

Description

@thesayyn

This issue is here to help people understand why I have created a new plugin that diversified the protocol buffer typescript community even more.

Q: Why would you create a plugin from scratch when you can fix problems on the upstream compiler?

A: Well it is not that simple because there is a lot of bureaucracy to make any of the design changes that I have done with this plugin. Even if we managed to pass that, there would be breaking changes that will not make design changes like this.



Q: Why should I use this plugin when I can use https://github.com/improbable-eng/ts-protoc-gen?

A: Keep in mind that "ts-protoc-gen" generates only d.ts binding which basically a type declaration file for the javascript output that has been generated by the official protoc compiler. This comes with a trade-off of not being able to customize the d.ts output as much as we like. If we did. it wouldn't match with the javascript file and you’d get a runtime error even though the typescript compiler wouldn’t complain about the javascript file being different than the d.ts file. So ts-protoc-gen has to match the javascript file which limits its ability to compile proto files to modern typescript syntax.



Q: How does protoc-gen-ts solve this problem?

A: By throwing away the javascript compiler of the official protoc compiler. Instead, we generate a typescript file (".ts" not "d.ts") which includes the runtime code that will run on the underlying javascript engine when it is running. Hence we have the ability to generate the proto files the way we want them.

There are a number of things that we do differently than the official protoc compiler that complies to javascript such as "generating files as typescript getter setter" which in turn you get the exact names that you have defined in the proto message. For instance, when you have a field named user_messages with the official compiler you'll get getUserMessages(). however, if you use this plugin, you’ll just access the property as is like user_messages.

Also, your enums will be generated as a typescript enum instead of an interface or object with predefined keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions