Protoc Gen Typescript
March 1, 2024 ยท View on GitHub
Compile .proto files to plain TypeScript. Supports gRPC Node and gRPC Web.
Note
As of 2024, this project has adopted Rust as its primary programming language, replacing JavaScript. See the issue for the details.
Contributing
I have limited availability to consistently maintain this project, as my time is primarily allocated to cutting new releases and implementing fixes on an ad hoc basis.
Become a maintainer? Send an email
Features
- Passes all required conformance tests
- Supports well-known types
- Supports gRPC (
@grpc/grpc-js) - Supports gRPC Web (
grpc-web) - Supports json encoding (
toJson,fromJson) - Supports binary encoding (
toBinary,fromBinary) - Optimized for [de]serialization speed.
Usage
npm install -g protoc-gen-ts
Protoc
protoc -I=sourcedir --ts_out=dist myproto.proto
Buf
version: v1
plugins:
- name: ts
path: ./node_modules/.bin/protoc-gen-ts
out: ./dist
Example
syntax = "proto3";
enum Role {
ADMIN = 0;
MOD = 1;
}
message Author {
Role role = 2;
oneof id_or_name {
string id = 4;
string name = 5;
}
}
const author = Author.fromJson({
role: Kind.ADMIN,
name: "mary poppins",
});
// Serialize to binary
const bytes: Uint8Array = author.toBinary();
// Deserialize from binary
const received: Change = Change.fromBinary(bytes);
console.log(received.toJson())
Development
./infra/test.sh
Contributors
Support
We need your constant support to keep protoc-gen-ts well maintained and add new features.
If your corporate has a OSS funding scheme, please consider supporting us monthly through open collective.