Open HenriBeck opened 4 years ago
If anyone else stumbles upon this, until this issue is resolved, https://github.com/stephenh/ts-proto implements oneof
in the exact way, as @HenriBeck suggests.
@Raiondesu @HenriBeck We have the same issue. But does the https://github.com/stephenh/ts-proto library work with grpc-web? Meaning, can you generate your stubs using the ts-proto
library, but then use them with the grpc-web
framework?
FYI - I'm guessing https://github.com/grpc/grpc-web/pull/1445 might be related here.
When started using
grpcweb
, we found the typings of aoneof
statement rather outdated and not type-safe.Problems
With the current typings being an object with just optional keys, we found it to be not very developer-friendly.
The above type doesn't make it clear that the
email
orpassword
can be set, and also doesn't prevent any misuse of the data.Solution
The best typing that we could come up with was the following:
These typings improve a few things:
switch/case
handling as it only allows to access the correct fieldsoneof
intent clearer as only one field could ever be setWould it be possible to change these types to something more modern utilizing some newer TS features?
Full example found here: https://codesandbox.io/s/youthful-surf-j0mz3?file=/src/index.ts