Missing some class definitions in the generated d.ts files.
See original GitHub issueI was trying the new d.ts generation feature (thanks again for adding it) and I found that in the generated definition file some of the types are declared as Objects when they could have been strongly typed. For instance, for the following .proto file:
syntax = "proto3";
service UserService{
rpc GetUser (GetUserRequest) returns (GetUserResponse);
}
message GetUserRequest {
string user_name = 1;
}
message GetUserResponse {
User user = 1;
}
message User {
string name = 1;
}
The produced _pb_d.ts file looks as follows:
export class GetUserRequest {
constructor ();
getUserName(): string;
setUserName(a: string): void;
serializeBinary(): Uint8Array;
static deserializeBinary: (bytes: {}) => GetUserRequest;
}
export class GetUserResponse {
constructor ();
getUser(): {};
setUser(a: {}): void;
serializeBinary(): Uint8Array;
static deserializeBinary: (bytes: {}) => GetUserResponse;
}
The getUser() method returns {} when it could be User
. The export class User
is missing as well. I was expecting something like this:
export class GetUserRequest {
constructor ();
getUserName(): string;
setUserName(a: string): void;
serializeBinary(): Uint8Array;
static deserializeBinary: (bytes: {}) => GetUserRequest;
}
export class GetUserResponse {
constructor ();
getUser(): User;
setUser(user: User): void;
serializeBinary(): Uint8Array;
static deserializeBinary: (bytes: {}) => GetUserResponse;
}
export class User{
constructor ();
getName(): string;
setName(a: string): void;
serializeBinary(): Uint8Array;
static deserializeBinary: (bytes: {}) => User;
}
Looking at the generator’s code, I see that only numbers and strings are being taken into account when printing class fields types. Other well known types like array
or map
aren’t being considered either.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:10 (2 by maintainers)
Top Results From Across the Web
[3.7.0] Generic class with private property generates d.ts file ...
Given that .d.ts files are typing info, if the error was removed (in 3.7+) that would mean that consumers of the API that...
Read more >About "*.d.ts" in TypeScript - Stack Overflow
The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using...
Read more >How to Declare Missing Types for External Libraries -- newline
Custom Types Declaration#. First, in your tsconfig.json add a directory path to type declarations:.
Read more >How would I add a type for missing type data in a library that ...
I'm using Express 4.17.2, and also using this library that makes formatting responses a little bit easier…
Read more >Working with JavaScript in Visual Studio Code
Using the TypeScript language service, VS Code can provide smart ... You will want to exclude files generated by a build process (such...
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
@aberasarte Thanks for the report. Yes we can certainly do better in the .d.ts typings output. Will work on this soon.
Looks like it not fixed.
@stanley-cheung can you provide some ETA for that bug?