protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.85k stars 1.41k forks source link

Add new target like `ts-module` #1250

Open redexp opened 5 years ago

redexp commented 5 years ago

What do you think about adding new target like ts-module to generate from proto like this

syntax = "proto3";

message User {
    int32 id = 1;
    string name = 2;
}

to ts like this

import {Message, Type, Field} from "protobufjs/light";

export interface UserInterface {
    id: number;
    name: string;
}

@Type.d("User")
export default class User extends Message<User> implements UserInterface {

    @Field.d(1, "int32")
    public id: number;

    @Field.d(2, "string")
    public name: string;

    public static verify(message: UserInterface) {
        return super.verify(message);
    }

    public static encode(message: UserInterface) {
        return super.encode(message);
    }
}
ghost commented 5 years ago

This might help https://github.com/improbable-eng/ts-protoc-gen