Skip to content

Add typescript target to pbjs #1580

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mdouglass
Copy link
Contributor

Well, clearly, this one is going to require a fair amount of discussion. We've been having ongoing problems with pbts because of various issues (see #998, #1217, #1414, etc). This PR removes the need for pbts (and the jsdoc dependency) by adding a typescript target to pbjs that directly generates a standard .ts file.

This PR should be considered only a proof of concept -- I wouldn't expect it to be merged as-is. But I wanted to judge the interest level in this (or something like it) before I spent more than the weekend on it.

In the current PR, this was done by forking static.js and modifying it to generate a TypeScript file. That's the real downside of the PR as-is, since a fair amount of the code is incredibly similar. I would be happy to look at instead modifying static.ts so that it can generate either JavaScript or TypeScript directly. I think the number of places that would need to be modified to handle that are relatively small.

There are also a few changes in typescript.js that cast to as any -- many of those are because of incorrect type definitions in protobuf's existing index.d.ts (particularly protobuf's Long is just a constructor and does not have the methods the real Long has).

@mdouglass mdouglass force-pushed the feat/typescript-target branch 4 times, most recently from fcc848f to 9e7c1f5 Compare April 5, 2021 23:18
Use an _ prefix in front of unused parameters so that the TypeScript generator
can signal to tsc that the parameter is unused and that is OK.
This is necessary because the TypeScript type is Message|undefined and null is
not a valid value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants