Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Wrong TypeScript type used for fields when name collision exists between imported and nested messages

オープン
#3,025 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
node.js, typescript
領域
tooling

調査の方向性

まず、報告されている proto-loader-gen-types コマンドを common.proto と service.proto に対して実行し、その後、生成された example/Service.ts を調べます。ネストされたメッセージの名前が同じ場合に、ジェネレーターが Resource をどのように解決するかを追跡し、生成されたフィールドがインポートされた型を使用し、そのインポートを含んでいることを確認します。

索引モデルが issue の本文から書いたものです。

説明

package: @grpc/proto-loader
Problem description

proto-loader-gen-types fails to disambiguate between imported top-level types and nested messages with the same name. When this collision occurs, it incorrectly uses the nested type, omits the required import, and generates types that don't match the protobuf structure. This causes type errors and breaks IDE autocomplete for affected fields.

Reproduction steps

Command:

npx proto-loader-gen-types --longs=String --enums=String --defaults --oneofs -I . --outDir=. common.proto service.proto

common.proto:

syntax = "proto3";
package example;

message Resource {
    int64 id = 1;
    string name = 2;
}

service.proto:

syntax = "proto3";
package example;
import "common.proto";

message Service {
    Resource resource = 1;  // Should reference Resource from common.proto
    
    message Status {
        message Metric {
            message Resource {  // Name collision
                string name = 1;
                int32 value = 2;
            }
        }
    }
}

Expected:

// example/Service.ts
import type { Resource as _example_Resource } from './Resource';

export interface Service {
  resource?: _example_Resource | null;  // Uses imported type
}

Actual:

// example/Service.ts
// Missing import for Resource

export interface Service {
  resource?: _example_Service_Status_Metric_Resource | null;  // Uses wrong nested type
}

Workaround - Manually add the import and fix the type:

import type { Resource as _example_Resource } from './Resource';

export interface Service {
  resource?: _example_Resource | null;  // Fixed
}
Environment

Reproduced with @grpc/[email protected] and @grpc/[email protected] on Ubuntu 22.04 on WSL2 (x86_64) with multiple 16+ Node versions. Node is installed using nvm

Additional context

Python and Go generators seem to handle this correctly:

# Python (protoc)
from example import common_pb2 as _common_pb2
class Service(_message.Message):
    resource: _common_pb2.Resource  # Correct
// Go (protoc-gen-go)
type Service struct {
    Resource *Resource  // Correct
}
// TypeScript (proto-loader-gen-types)
resource?: _example_Service_Status_Metric_Resource | null;  // Wrong
主要言語
TypeScript
スター
4.8k
フォーク
717
平均マージ
1日 18時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

grpc/grpc-node のほかの issue

grpc/grpc-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。