feat: allow strings for enums, bytes, and Long in .d.ts #714
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.
Fixes googleapis/gapic-generator-typescript#196, googleapis/nodejs-tasks#334, googleapis/nodejs-iot#250, googleapis/nodejs-scheduler#181, googleapis/nodejs-tasks#331 (and maybe more).
TL;DR
We will accept enum string values in TypeScript request and response types, just like our JavaScript samples suggest to do.
More details
In this PR I'm updating the
compileProtos
tool so that the request and response types accepted strings for enums,bytes
, andLong
. For enums, I'm using the magickeyof typeof
TypeScript feature to only allow proper strings as values. Forbytes
,protobuf.js
allows passing arbitrary string (it will base64-decode it). ForLong
,string
is also accepted with our current set of options.Example
This
.d.ts
file from Speech API will have the following changes. I verified that with these changes it's possible to pass a string (e.g."FLAC"
) as an encoding.