ts-proto
ts-proto copied to clipboard
TS errors with ts-proto using grpc-web
My goal is to communicate from the browser (Angular) to a C# backend. For that I'd like to use the grpc-web style using option
--ts_proto_opt=outputClientImpl=grpc-web
Using it produces Typescript errors in all fromPartial
methods for all properties saying property x does not exist on I
so I decided to remove the fromPartial
methods since they are not that essential for me by using the option
--ts_proto_opt=outputPartialMethods=false
which resulted in a file where the fromPartial
methods do not exist any more but they are still used in other places.
Can you give me advice on what to do to use grpc-web style or what I am doing wrong?
grpc-web option only
Created by using:
sudo protoc --ts_proto_opt=outputClientImpl=grpc-web --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. -I <myFolder> accounting.proto
For I
it says:
Type 'I' does not satisfy the constraint '{ id?: number | undefined; valutaDate?: Date | undefined; remarks?: string | undefined; receiptHistoryId?: number | undefined; bookings?: { id?: number | undefined; paidFromAccount?: { ...; } | undefined; paidToAccount?: { ...; } | undefined; amount?: number | undefined; remarks?: string | undefined; bookingType?: B...'.
Type 'unknown' is not assignable to type '{ id?: number | undefined; valutaDate?: Date | undefined; remarks?: string | undefined; receiptHistoryId?: number | undefined; bookings?: { id?: number | undefined; paidFromAccount?: { ...; } | undefined; paidToAccount?: { ...; } | undefined; amount?: number | undefined; remarks?: string | undefined; bookingType?: B...'.ts(2344)
Record
is nested by the way
message Record{
int64 id = 1;
google.protobuf.Timestamp valutaDate = 2;
string remarks = 3;
int64 receiptHistoryId = 4;
repeated Booking bookings = 5;
}
grpc-web option combined with the no partial option
Created by using:
sudo protoc --ts_proto_opt=outputClientImpl=grpc-web --ts_proto_opt=outputPartialMethods=false --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. -I <myFolder> accounting.proto
Used versions
- protoc-3.15.8-linux-x86_64.zip
- ts-proto 1.115.5 (npm)
Workaround: I use
--ts_proto_opt=useExactTypes=false
@HypeillingerChillinger we've bumped the version of typescript; can you try the latest version of ts-proto and see if that fixes the error with useExactTypes
? Thanks!