0.1.3 • Published 7 months ago

proto-to-ts-type v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

proto-to-ts-type

This library will generate TypeScript types from .proto files. This does not generate other features like binary serializing/deserializing, toJson/fromJson or other stuff like that.

how to use

  1. install package
yarn add --dev proto-to-ts-type
  1. execute protoc command
  • without option
protoc \
  --plugin="./node_modules/.bin/protoc-gen-ts-type" \
  --ts-type_out=. \
  proto.proto
  • with options

For example, If you'd like to generate json_name defined in protofiles as TS type fields and enum as string, execute the following command.

Each the pair of key and value is supposed to be delimited by equal sign =, and comma , for each parameters.

protoc \
  --plugin="./node_modules/.bin/protoc-gen-ts-type" \
  --ts-type_out=. \
  --ts-type_opt=useJsonName=true,enumValueAsString=true \
  proto.proto

Available option

Check in src/option.ts.

keyvalue
useJsonNametrue/falsejson_name in a proto file would be used.
enumValueAsStringtrue/falseEnum value would be same as member names instead of numbers, which starts with 0
useTypeGuardForOneOftrue/falseIf true, add type guard functions for oneof operation, or optional properties.

The mapping rules of proto to TypeScript types

protoTypeScript
doublenumber
floatnumber
int32number
uint32number
sint32number
fixed32number
sfixednumber
int64bigint
uint64bigint
sint64bigint
fixed64bigint
sfixed64bigint
stringstring
boolboolean
grouptype_name of FieldDescriptorProto
enumtype_name of FieldDescriptorProto
messagetype_name of FieldDescriptorProto

dependencies

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.1

7 months ago