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

toJson return value inferred as JsonValue when passing any options #993

Open
lourd opened this issue Oct 22, 2024 · 1 comment
Open

toJson return value inferred as JsonValue when passing any options #993

lourd opened this issue Oct 22, 2024 · 1 comment

Comments

@lourd
Copy link

lourd commented Oct 22, 2024

I'm trying out the connect-es v2 RC with @bufbuild/protobuf 2.2.0.

When passing any available options to the toJson function, the return type is inferred as JsonValue instead of the {Message}Json type. This happens regardless of whether or not the json_types option is set to true for the protoc-gen-es.

Screenshot 2024-10-22 at 12 28 40 AM

The expected outcome here is that the return type is the {Message}Json type; the ideal outcome is that the type also takes into account the options given and infers more specific types, e.g. when enumAsInteger is given, any enums are a number in the type.

@timostamm
Copy link
Member

You have to specify the options literal with as const, see https://github.com/bufbuild/protobuf-es/blob/v2.2.0/packages/protobuf/src/to-json.ts#L143.

But you'll only get the JSON type for the standard options, since that's what the generated JSON type matches.

I agree that it would be ideal if the returned type honored non-standard options, but unfortunately I don't see how we could support that.

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