Generate purely typescript interfaces / plain JSON representation
See original GitHub issueUnfortunately, discussions aren’t available for this repo and i’m not sure if this feature is out of scope or not.
Basically, I noticed that for large protocols, protobuf bundle size can go to upwards of 50kB. Considering that JSON serialization/deserialization is also accelerated by the browser’s native code, I feel like it may be more beneficial for us to use purely the JSON representation of the protobuf for RPCs.
Is it possible for protobuf-ts
to support generating exclusively typescript interfaces and using JSON.parse
/ JSON.stringify
for serialization? This could significantly lower bundle size for web apps.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why you should generally prefer TypeScript interfaces and ...
If you decide to use classes to represent your data model, then you'll have to deserialize (i.e., convert) the received JSON data into...
Read more >How We Use Our Typescript Type Information at Runtime
The JSON Schema that you'll end up with is an accurate representation of your Typescript classes, interfaces, properties, type aliases, ...
Read more >How to Cast a JSON Object Inside of TypeScript Class
Plain objects: When we try to parse JSON data using JSON.parse() method then we get a plain object and not a class object....
Read more >A simple guide to “interface” data type in TypeScript - Medium
An interface tells the TypeScript compiler about property names an object can have and their corresponding value types. Therefore, interface is a type...
Read more >Documentation - Object Types - TypeScript
In JavaScript, the fundamental way that we group and pass around data is through objects. In TypeScript, we represent those through object types....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is actually already available! At least the core functionality. It is not documented and the API is not streamlined at all, but it works.
This means it is possible to create something like proto-loader with protobuf-ts. There just needs to be a piece of code that reads proto loader json files and turns them into file descriptors.
I do have an idea to reduce code size further. At the moment, all functionality is packed into
MessageType
and can’t be shaken off if you don’t need it.Moving the methods to standalone functions would mean that webpack output for example would not contain code for the JSON format if you only use the binary format.
This opens up several design questions though. I think this might be thing for v3…