A protoc plugin that generates typescript messages and service defitions. Notably: the generated messages can use native JSON serialization on a browser and do not require any generated marshalling code. The marshalling format is standard JSON Mapping.
- Install protoc
go install github.com/fullstorydev/protoc-gen-typescript/...@latestprotoc --typescript_out=<output dir> ...
Enums are represented by integers, not strings, for both efficiency and version compatibility.
TODO: notes about oneof.
See for more info: JSON Mapping.
| Proto type | Typescript Type | Wire format |
|---|---|---|
int64 |
protobuf.int64 |
string* |
int32 |
number |
number |
uint32 |
number |
number |
sint32 |
number |
number |
fixed32 |
number |
number |
sfixed32 |
number |
number |
sint64 |
protobuf.int64 |
string* |
uint64 |
protobuf.uint64 |
string* |
fixed64 |
protobuf.uint64 |
string* |
sfixed64 |
protobuf.int64 |
string* |
float |
number |
number |
double |
number |
number |
bool |
boolean |
boolean |
string |
string |
string |
Empty |
{} |
`{} |
Timestamp |
protobuf.timestamp |
string* |
Duration |
protobuf.duration |
string* |
Any |
object |
json |
Struct |
object |
json |
Value |
unknown |
json |
ListValue |
unknown[] |
json |
- Note: string wire format requires converstion to useful types, see below
You will need typescript definitions for:
- protobuf.timestamp
- protobuf.duration
- protobuf.int64
- protobuf.uint64
There are helper methods to correctly convert between these wire format types and more useful Typescript representations.
TODO: notes about proto service definitions.
TODO: notes about Go service integration and GRPC.