TypeScript type generation wrong when using multiple files
See original GitHub issueI’m currently migrating my GRPC service declarations from JS to Typescript and noticed that the code generation is wrong when referencing messages/types from other files.
Given the code below, the following MyServiceServiceClientPb.ts
is generated:
...
methodInfoaddOne = new grpcWeb.AbstractClientBase.MethodInfo(
MyMessagesFile_pbInteger,
(request: MyMessagesFile_pbInteger) => {
return request.serializeBinary();
},
MyMessagesFile_pbInteger.deserializeBinary
);
...
Note the correct type is MyMessagesFile_pb.Integer
(the dot is missing)!
This is printed in grpc_generator.cc:713
.
Using libprotoc 3.11.1
and grpc-web 1.0.7
MyServiceFile.proto
syntax = "proto3";
import "MyMessagesFile.proto";
service MyService {
rpc addOne(Integer) returns (Integer);
}
MyMessagesFile.proto
message Integer {
int32 number = 1;
}
package.json
{
...
"scripts": {
...
"grpc-generate": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '1s;^;/* eslint-disable */;' $f; done",
"grpc-generate-macos": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '' '1s;^;/* eslint-disable */;' $f; done",
...
}
...
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How do I split a TypeScript class into multiple files?
I have found many times that partial classes separated across many files are very useful. this is true primarily when you have a...
Read more >TSConfig Reference - Docs on every TSConfig option
Intro to the TSConfig Reference. A TSConfig file in a directory indicates that the directory is the root of a TypeScript or JavaScript...
Read more >TypeScript library tips: Rollup your types! | by Martin Hochel
There are various options on the market, most familiar are probably webpack and ... By default, TypeScript wont emit declaration files.
Read more >Generate GraphQL Types with Apollo Codegen Tutorial
TypeScript GraphQL Code Generator – Generate GraphQL Types with Apollo ... our queries and mutations to tell if we're doing something wrong.
Read more >TypeScript | WebStorm Documentation - JetBrains
TypeScript files are marked with the TypeScript file ... completion for keywords, labels, variables, parameters, and functions, error and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure, it’s not very generic though. It’s just doing an explicit find/replace on the string in all the .ts files.
in our bash script:
Unfortunately the fix does not seem to cover the “enum” entries defined in the imported proto. The “.” is still missing for them using release 1.2.1