Skip to content

[Feature Request]: proto-loader-gen-types: More options for generated code #2907

@RainmanVi

Description

@RainmanVi

Is your feature request related to a problem? Please describe.

After extensive trial and error, I found that proto-loader-gen-types is the simplest solution for generating type definitions for code that uses @grpc/grpc-js in TypeScript.

But the TypeScript code generated by proto-loader-gen-types has the following issues:

  1. The file extension is .ts, but since it is meant for type declarations, it is supposed to be .d.ts instead.
  2. With module": "nodenext" set in tsconfig.json and "type": "module" set in package.json for Node projects, VS Code raises warnings about missing file extensions in import module specifiers. When using ESM in Node, both Node.js and TypeScript's module resolution require explicit file extensions in import paths. However, the code generated by proto-loader-gen-types does not automatically include them. This results in a manual update step after code generation, which is inconvenient and an antipattern.

Describe the solution you'd like

  1. Provide an option to configure which file extension (.ts or .d.ts) is used for generated code. Maybe something like this
  2. Provide an option to configure whether file extensions are appended to module specifiers in generated code. Maybe something like this

Additional context

There are related discussions, such as #2693 and #2401. This issue aims to revive the topic and encourage further discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions