ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

Support for FieldOptions.JSType

Open beyers-luno opened this issue 1 year ago • 5 comments

Reference: https://protobuf.dev/reference/java/api-docs/com/google/protobuf/DescriptorProtos.FieldOptions.JSType

Hi!

In my proto file I have:

int64 foobar = 3 [jstype = JS_STRING];

In my generated ts file I get:

foobar: number;

Using the arguments:

--ts_proto_opt=onlyTypes=true

It should be this?

foobar: string;

Is there a configuration setting I am missing?

beyers-luno avatar Oct 26 '23 09:10 beyers-luno

The closest configuration setting I can find is forceLong=string, which isn't exactly the same thing.

beyers-luno avatar Oct 26 '23 10:10 beyers-luno

Hi @beyers-luno , you're right, we don't currently support jstype--this is the first I'm seeing it.

Happy to have you work on a PR if you'd like to add support for it, although I'm a little worried it might be complicated, like I'm not sure the matrix of "proto type <-> different jstype". I assume that's documented somewhere, but just might be tedious to handle all of the cases.

Would be great if you want to take a look though; thanks!

stephenh avatar Oct 26 '23 21:10 stephenh

I'd be willing to take a stab at this

dasco144 avatar Apr 12 '24 16:04 dasco144

@dasco144 sounds good!

I think the toTypeName in types.ts is probably the best slice-point to say "this field should actually be type xyz".

Unfortunately that's just the type, and the encoding/decoding of that type is probably scattered around the encode/decode/toJSON/fromJSON methods. Like getEncodeWriteSnippet and getDecodeReadSnippet.

stephenh avatar Apr 13 '24 18:04 stephenh

@stephenh I've got an PR ready for review 🙏

dasco144 avatar Apr 16 '24 15:04 dasco144

:tada: This issue has been resolved in version 1.173.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

stephenh avatar Apr 30 '24 04:04 stephenh