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

Remove $typeName and $unknown #1016

Closed
netanel-utila opened this issue Nov 10, 2024 · 3 comments
Closed

Remove $typeName and $unknown #1016

netanel-utila opened this issue Nov 10, 2024 · 3 comments

Comments

@netanel-utila
Copy link

Hi,

Is there any way to exclude $typeName and $unknown from the types? we don't want to expose this to our clients:

Screenshot 2024-11-10 at 16 25 29

Thanks

@timostamm
Copy link
Member

You can remove properties (and do much more) with mapped types.

Here is an example for a Connect client that does not make properties optional, and strips the $typeName and $unknown properties: https://github.com/connectrpc/examples-es/tree/main/custom-client

The OmitTypeName type from this example might just be what you need.

@netanel-utila
Copy link
Author

I understand that it's possible to implement this; however, same as the timestamp issue, I thought this could be something incorporated as a plugin or something. This way, it would automatically generate the desired outcome and we won't need to create wrappers, etc.

@timostamm
Copy link
Member

Do you mean a plugin option to disable $typeName and $unknown?

ts-proto has many plugin options and basically no runtime library. Protobuf-ES has a different approach - it generates very little code, hosts most functionality in the runtime library, and aims for a single way to do things. The practical advantage is that we can test correctness, which is infeasible with a large number of plugin options that can affect each other.

Depending on your use case, it might be worth to write a Protobuf plugin that emits types without $typeName 🤔

Regardless of the concrete way to disable $typeName, we're aware that the property has disadvantages. Closing as a duplicate of #994, which tracks making it optional.

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