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

TypeScript: an import resolves to a same-named method of an exported object literal instead of the exported function

オープン 初心者向け
#2,945 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@inth3shadows がすでに取り組んでいます。

2026年10月28日 から。

  • #2990 @inth3shadows による — オープン

評価

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

調査の方向性

src/resolution/import-resolver.ts の getFileExportIndex、279 行目あたりから始めてください。ここでは名前ごとに最初のエクスポートされたノードが優先され、オブジェクトリテラルのメソッド hashDriver::symbolHref が実際のエクスポートを隠します。2 ファイルの nav.ts/walk.ts フィクスチャで再現し(issue に正確な形が示されています)、次に提案されたタイブレークを適用して比較し、__tests__/ui-package.test.ts と import/export/reexport/barrel/commonjs のスイートを CODEGRAPH_KERNEL=0 で実行してください。完了とは、walkTo が nav.ts:6 にリンクし、それらのスイートがグリーンのままであることを意味します。

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

説明

import { f } from './m' resolves to a method named f inside an exported object literal in m.ts, instead of m.ts's exported function f, when the object comes first in the file.

// nav.ts
export interface Driver { symbolHref(id: string): string; }
export const hashDriver: Driver = {
  symbolHref(id) { return '#' + id; },          // line 3
};
let driver: Driver = hashDriver;
export function symbolHref(id: string): string { return driver.symbolHref(id); }   // line 6

// walk.ts
import { symbolHref } from './nav';
export function walkTo(id: string) { return symbolHref(id); }
expected actual
walkTo calls symbolHref at nav.ts:6 symbolHref at nav.ts:3 (hashDriver::symbolHref, resolvedBy: import)

Reproduced on main at 31ec9082 with CODEGRAPH_KERNEL=0, and on 69af19ac with the native kernel too (Linux/WSL2, Node 22.23.2). The same thing happens in this repo: ui/src/lib/walk.ts calls symbolHref/navigate, and __tests__/ui-package.test.ts calls symbolHref/fileHref/mapHref/flowHref. All of them land on hashNavigation's methods in ui/src/lib/navigation.ts (lines 123–187) rather than the exported functions at lines 240–272.

Cause. The object's method is indexed as function symbolHref, isExported = 1, qualifiedName hashDriver::symbolHref (presumably through the object-literal extraction for an exported const). getFileExportIndex keeps the first exported node per name (import-resolver.ts#L279), so the method shadows the real export.

Possible fix. When two exported nodes share a name, let a top-level declaration replace a member:

const prev = idx.byName.get(n.name);
if (!prev || (prev.qualifiedName !== prev.name && n.qualifiedName === n.name)) idx.byName.set(n.name, n);

With that change walkTo links to nav.ts:6, and the 62 __tests__ files matching import/export/reexport/barrel/store/commonjs/require/default pass (490 tests, CODEGRAPH_KERNEL=0). I haven't run the full suite, and a stricter version might keep members out of byName entirely.

Not fixed by #2754 or #2800: I ran this fixture on both heads and the edge still lands on line 3. I also searched open issues and PRs for object-literal methods and import namesakes, and found nothing else that covers it.

主要言語
C
スター
73.2k
フォーク
4.7k
平均マージ
3時間 13分
マージ済み PR(30日)
579

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

colbymchenry/codegraph のほかの issue

colbymchenry/codegraph の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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