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

useOptionals for oneofs fields #548

Open
Larkooo opened this issue Apr 13, 2022 · 1 comment
Open

useOptionals for oneofs fields #548

Larkooo opened this issue Apr 13, 2022 · 1 comment

Comments

@Larkooo
Copy link
Contributor

Larkooo commented Apr 13, 2022

It is quite annoying and tedious that a oneofs fields do not default to being optional as it triggers typescripts type safety. However, it could easily be fixed if optionals were used by default for a oneofs fields without needing to enable the useOptionals option, as it also allows other fields to be optional.

We could perhaps extend the useOptionals option to only allow oneofs fields to be optional or just check if the property is within a oneof and directly make it optional
https://github.com/stephenh/ts-proto/blob/main/src/main.ts

export function isOptionalProperty(

@stephenh
Copy link
Owner

Hm, yeah, @Larkooo I'd generally recommend using the oneof=unions option, which should probably be the default, but in the case of oneof=unions not being in use, having optional keys for oneof properties seems reasonable. If you want to work on a PR, that'd be great.

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