Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add custom imports for pbts generated types #1034

Open
thegecko opened this issue Apr 29, 2018 · 3 comments
Open

Unable to add custom imports for pbts generated types #1034

thegecko opened this issue Apr 29, 2018 · 3 comments

Comments

@thegecko
Copy link
Contributor

protobuf.js version: master

When using a custom target for pbjs I expect to be able to have generated classes inherit from a custom base class (as opposed to something from the protobufjs codebase, e.g. protobuf.Rpc.Service).

This can be achieved by writing out a require in the template, but when it comes to generating the types with pbts, the requires are lost and tsc fails.

I see there is a hardcoded import added by pbts:

https://github.com/dcodeIO/protobuf.js/blob/master/cli/pbts.js#L146

JSDoc doesn't seem to support imports/requires, so is there a way to add custom imports?

@thegecko thegecko changed the title Unable to add imports for pbts generated types Unable to add custom imports for pbts generated types Apr 29, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Apr 29, 2018

I think this'd require some sort of postprocessing at this point, but a mechanism that somehow inherits custom imports from JS in the generated TSD would be ideal, probably.

@thegecko
Copy link
Contributor Author

Ultimately I'm trying to create an abstract class for implementing RPC server templates and this is the final hurdle.

I can approach this in different ways:

  • Create a PR containing a new generic target and base class alongside protobufjs.Rpc.Service
  • Keep it a custom implementation, which will require the imports to be fixed:
    • Fix imports by inventing a new extension to the jsdoc markup (@import perhaps) to be processed by pbts
    • Fix imports by allowing a list of imports to be passed to the pbts tool

I think I'd prefer to see the import syntax included in the target as it keeps the concerns together. Therefore the jsdoc extension approach could be better. I can then share my server work if of interest later.

Any preference?

@thegecko
Copy link
Contributor Author

Perhaps abuse the @external tag:

http://usejsdoc.org/tags-external.html

This was referenced May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants