Giter Site home page Giter Site logo

proto-to-ts-type's Introduction

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.

key value
useJsonName true/false json_name in a proto file would be used.
enumValueAsString true/false Enum value would be same as member names instead of numbers, which starts with 0
useTypeGuardForOneOf true/false If true, add type guard functions for oneof operation, or optional properties.

The mapping rules of proto to TypeScript types

proto TypeScript
double number
float number
int32 number
uint32 number
sint32 number
fixed32 number
sfixed number
int64 bigint
uint64 bigint
sint64 bigint
fixed64 bigint
sfixed64 bigint
string string
bool boolean
group type_name of FieldDescriptorProto
enum type_name of FieldDescriptorProto
message type_name of FieldDescriptorProto

dependencies

proto-to-ts-type's People

Contributors

yo-mah-ya avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.