An EXTREMELY OPINIONATED Protoc Plugin for generating TypeScript Declarations from Protocol Buffer schema.
This repository contains a protoc plugin that generates TypeScript declarations
(.d.ts
files) that match the JavaScript output of protoc --js_out=import_style=commonjs,binary
.
This plugin is tested and written using TypeScript 2.7.
This repository is forked from https://github.com/improbable-eng/ts-protoc-gen/
As a prerequisite, download or install protoc
(the protocol buffer compiler) for your platform from the github releases page or via a package manager (ie: brew, apt).
For the latest stable version of the ts-protoc-gen plugin:
npm install protoc-ts-type-gen
Run protoc and reference this library as a plugin:
protoc \
--plugin="protoc-gen-ts=node_modules/.bin/protoc-ts-type-gen" \
--ts_out="${OUT_DIR}" \
your proto files
By default the google-protobuf library will use the JavaScript number type to store 64bit float and integer values; this can lead to overflow problems as you exceed JavaScript's Number.MAX_VALUE
. To work around this, you should consider using the jstype
annotation on any 64bit fields, ie:
message Example {
uint64 bigInt = 1 [jstype = JS_STRING];
}