Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Working example(s)? #19

Open
btgoodwin opened this issue Nov 8, 2016 · 5 comments
Open

Working example(s)? #19

btgoodwin opened this issue Nov 8, 2016 · 5 comments

Comments

@btgoodwin
Copy link

I've searched for days for a working example of how someone has used this library to work with protocol buffers in TypeScript and have come up with nothing. The example provided in the README.md also indicates a method on ProtoBuf (protobufjs, I assume) that does not presently exist in that library (protoFromFile). I admit I'm still learning all the nuances of TypeScript and project configurations, however it would be great to see the source code of a working example for using this library and protobufs in general.

For my particular use case, I have a library that I'm porting from JS/Angular1 to TS/Angular2 as a ES2015 module, and it has some protocol buffers defined in it. I've tried going through the process of converting the proto files to JSON, and then from JSON to typings definitions as indicated in the README.md. I then installed those definitions (d.ts) into my global typings (typings install --global --save file:<path>/file.d.ts). When I then try to reference the default module name generated by this tool, Proto2TypeScript, in my TypeScript files, I get: Cannot find namespace 'Proto2TypeScript'. I also cannot import that module name, etc. which leaves me wondering what part of this process is actually broken since there is no end-to-end example that I can find.

@btgoodwin
Copy link
Author

I've been working with this all day and have nothing. When I reference and import the definition typescript file, I end up with dozens of errors from TypeScript indicating problems like "Declaration or statement expected" etc. which indicate to me the file format generated by Proto2Ts is incorrect.

Are there some other constraints to using this library? Like only protobuf 3.x definitions?

@fungiboletus
Copy link
Member

Hei, I'm sorry to hear that. I don't use this library anymore and I don't exactly know in which state it is with the latest releases of Protobuf, Protobuf.js, and TypeScript. It looks like some work is required.

@btgoodwin
Copy link
Author

Did you move on to something more effective/up to date?

When you did use the library, was the workflow for this?

  1. Generate the descriptor (d.ts) file
  2. Add it to typings (typings install --global --save file:d.ts)
  3. Add to your TS file: import { SomeExportedInterface } from 'ModuleName' // declared in the d.ts

@btgoodwin
Copy link
Author

The problem it's having is type extensions. For example:

message SuperType {
    extensions 101 to max;
    enum TYPE {
        option allow_alias = true;
        Type1 = 1;
        // etc.
    }
    required TYPE type = 1;
}

message SubType {
    extend SuperType {
        optional SubType supertype = 101;
    }
   // Some special field for this type
}

I'm poking around in the DUST templates now to see if I can clarify this.

@fungiboletus
Copy link
Member

I don't use Typescript anymore in my professionnals projects :(

I merge pull requests time to time, but because I am not an user of this tool, I don't really know in which state it is with the recent versions.

When I used the library, it wasn't with ES2015 and typings, so I did most of the things by hand. I don't know whether type extensions are working. You can check the DUST templates yes :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants