grpc-web
grpc-web copied to clipboard
Some types generated from `oneof` should always be required?
Hi folks, when started using grpc-web, I found that some types are always required in AsObject
, but I'm wondering shouldn't they be optional?
Problem
Here's the repo I created to explain the problem I have: https://github.com/mkfsn/protoc-gen-grpc-web-oneof
I first define the message like this:
message Echo {
string id = 1;
int64 type = 2;
oneof element {
string text = 16;
double numeric = 17;
}
}
(See also: https://github.com/mkfsn/protoc-gen-grpc-web-oneof/blob/d0df6d0a3c526491373d5ab24a539c2ac2c7efc7/echo.proto#L7-L10)
And then I run the command to generate the typescript file:
protoc -I=. echo.proto \
--grpc-web_out=import_style=typescript,mode=grpcwebtext:.
(See also: https://github.com/mkfsn/protoc-gen-grpc-web-oneof/blob/main/Makefile#L2-L3)
After that I'm getting the following results in the _pb.d.ts
file:
export namespace Echo {
export type AsObject = {
id: string,
type: number,
text: string,
numeric: number,
}
export enum ElementCase {
ELEMENT_NOT_SET = 0,
TEXT = 16,
NUMERIC = 17,
}
}
(See also: https://github.com/mkfsn/protoc-gen-grpc-web-oneof/blob/d0df6d0a3c526491373d5ab24a539c2ac2c7efc7/echo_pb.d.ts#L32-L33)
I'm wondering shouldn't text
and numeric
be optional like:
text?: string,
numeric?: number,
I'm using version grpc-web 1.2.1
and using macos.
I'm not sure if this is intended or not, can anyone confirm this with me? Sorry if I'm wrong.