Wrong TypeScript type used for fields when name collision exists between imported and nested messages
メンテナーはふだん 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 の本文から書いたものです。
説明
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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
grpc/grpc-node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
package: @grpc/grpc-js
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
grpc/grpc-node#2993 · コメント 3 件 · リアクション 4 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
grpc/grpc-node#3091 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
feature request
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
grpc/grpc-node#3077 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
grpc/grpc-node#3068 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
callstackincubator/rozenite#518 ·
メンテナーはふだん 1 日以内に返信
-
Area/Workflow Priority/Blocker Type/Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
wso2/product-integrator#2622 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
area:bash bug has repro platform:macos
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
anthropics/claude-code#98644 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
allure-framework/allure-js#1603 ·
メンテナーはふだん 1 日以内に返信