node.js and typescript
Great to see you have JS support for browsers and node.js. However, for those of us writing with typescript (for either browser or node.js) it would be very helpful to have a typescript definition file (.d.ts file).
Possible?
Yes, that would be very welcome. @mprobst suggested to me that we could use http://github.com/angular/clutz to generate TypeScript interfaces from our Closure-annotated source code.
@haberman IMHO it might be a bit too much effort for a project that's not already using Closure to set up the infrastructure to run clutz (java, Closure, build system deps). I think it might still be worth having a compiler (mode) that produces .d.ts files.
@mprobst :+1: - we're currently generating .d.ts files using a separate compilation process.
@myitcv are there any public pointers to how we could do something like that?
@LoungeFlyZ - nothing public yet. Not for lack of want or trying... just that other things are getting in the way at the moment.
+1 for typescript
If there are any clutz + protobuf experts out there, I'm currently slogging through setting that up for CockroachDB. Your help would be appreciated over in https://github.com/angular/clutz/issues/334!
Any progress on this so far?
Would it be possible for the Protocol Buffers team to share their plans for adding typescript support? Specifically,
- Generating .d.ts (aka Typescript definition files) from the compiler, as pointed out by @mprobst - tracked here.
- Supporting protobufs in the browser (which are then imported into a client-side typescript framework) - javascript part tracked via protocolbuffers/protobuf-javascript#91.
- Documenting the workflow for a novice/beginner on the browser side - again tracked via protocolbuffers/protobuf-javascript#91.
The base case for the above request is that of using protobufs in Angular typescript. In case the team wants me to open separate tracking bugs for typescript for points 2) and 3) above, please let me know.
@mprobst does your team have a vision for how this should work? It seems like the strategy for generating TypeScript protobuf code and consuming it client-side projects is still not really documented or implemented yet. Could someone with a grasp of what effort remains explain what still needs to be done?
I'm trying to consume generated protobuf code for an Angular/Bazel/Closure app written in TypeScript, and I think protobuf support is one of the last missing pieces. I noted in https://github.com/bazelbuild/rules_typescript/issues/116 that adding a closure_js_proto_library rule as a dependency on a ts_library doesn't currently work--but I'm not sure if fixing that rule is the best approach, or if the protobuf or rules_typescript contributors have a different approach in mind.
@pshields we don't have a good open source answer. Internally, we use the proto->JS generator, and then use https://github.com/angular/clutz to convert that to TypeScript definitions. But you're right, that hasn't been open sourced, so it doesn't work with closure_js_proto_library.
I also suspect that if you're not using that generator for other reasons, you might be better off with a different solution. If I remember correctly, protobufjs has support for generating TypeScript code, but I've never used it.
/CC @alexeagle who might have something cooking here.
I'd rather not use Closure codegen if we want TypeScript types. Clutz is complex, and I don't want to ever introduce it under Bazel, because I don't know of any Bazel users who continue development of Closure JS code along with their TypeScript.
https://github.com/bazelbuild/rules_typescript/issues/61 is what I intend to do, which would generate .d.ts from .proto. Bazel users should adopt the best of the existing open source tools to solve a given problem, not adopt the Google-authored tool by default.
Any progress on this in 2k18?
Under Bazel, we have a ts_proto_library rule in http://tsetse.info/api/protobufjs/ts_proto_library.html
which generates the .d.ts files for typechecking. It's very simple to add this as a dependency of a ts_library.
This uses https://github.com/dcodeIO/protobuf.js#pbts-for-typescript under the covers. If you don't use Bazel, you could use that library directly to generate .d.ts files, assuming you use the corresponding generator for the .js runtime files. (That's because client generation has some degrees of freedom in how they name the api methods, and the .d.ts needs to match)
This is not the only way to do protocol buffers, but it's the one we are supporting under the Angular toolchain for now.
For what it's worth I have a typescript generator here: https://godoc.org/github.com/tmc/grpcutil/protoc-gen-tstypes
Considering Google has mentioned NestJS and is building Angular in Typescript I think it'd only make sense for protobuf to support some form of Typescript natively?
Has there been any change since last year about the stance this project has on Typescript?
We have a plugin that is maintained by me and people from the community;
https://github.com/thesayyn/protoc-gen-ts
This is a reasonable, but substantial FR that we are unlikely to get to soon.