use enums in function signatures within typescript definitions #2242
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt at fixing #2154 by generating TypeScript definitions that use the correct type for enums within function arguments and return types rather than just
number
.I’m quite unfamiliar with this codebase so it’s very possible that my approach will require further tweaks, but I hope it’s at least a good start.
I’ve adapted the backend crate’s
codegen
module to output thejs_name
for Enums within the descriptor and likewise adapted the cli-support crate to load that information. To have it appear in the TS definitions, I’ve addedAdapterType::Enum(String)
which compiles to the same adapter code but carries the name alongside it.I’ve also added a new pair of files to the typescript_tests crate to handle these cases.