protoc-gen-grpc-gateway-ts
protoc-gen-grpc-gateway-ts copied to clipboard
Generated TS types for google.protobuf.Timestamp do not match grpc-gateway encoding
Context
I am using some messages in my protos tha use the well-known google.protobuf.Timestamp:
message Timestamp {
// Represents seconds of UTC time since Unix epoch
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
// 9999-12-31T23:59:59Z inclusive.
int64 seconds = 1;
// Non-negative fractions of a second at nanosecond resolution. Negative
// second values with fractions must still have non-negative nanos values
// that count forward in time. Must be from 0 to 999,999,999
// inclusive.
int32 nanos = 2;
}
Issue
When using grpc-gateway + grpc-gateway-ts to generate both the Go server and the TS client respectively, the following type is generated:
export type Timestamp = {
seconds?: string
nanos?: number
}
However, the Go server encodes the timestamp as a string! (checked the received body in the network tab)
For now, I am manually replacing the generated timestamp.pb.ts
for the following:
export type Timestamp = string
I am not entirely sure if the best solution is to fix the client side or the server side in this case...