question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing some class definitions in the generated d.ts files.

See original GitHub issue

I 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:open
  • Created 5 years ago
  • Reactions:10
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
stanley-cheungcommented, Sep 7, 2018

@aberasarte Thanks for the report. Yes we can certainly do better in the .d.ts typings output. Will work on this soon.

4reactions
pumanocommented, Nov 13, 2018

Looks like it not fixed.

@stanley-cheung can you provide some ETA for that bug?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found