microsoft / microsoft/TypeScript

Invalid import path rewrite in declaration file

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

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

Bug Domain: Declaration Emit Help Wanted
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

"import paths", "imports rewrite"

🕗 Version & Regression Information
  • This changed between versions 5.5.4 and 5.6.3
⏯ Repository with repro

https://github.com/MariaSolOs/path-rewrite-bug

💻 Code

The linked repository contains all of the necessary code to reproduce the issue. This is a pnpm monorepo with 4 packages.

mod1 simply exports the following interface and makes it available outside the package:

// mod1/index.ts
export interface Foo {
  foo: string;
}
// mod1/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  }
}

mod2 depends on mod1 and exports its types.

// mod2/index.ts
import { Foo } from "mod1";

export const createFoo = (foo: string): Foo => ({ foo });

export type * from "mod1";
// mod2/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod1": "workspace:*"
  }
}

mod3 depends on mod2 and exports a simple getFoo function using the imported function from mod2:

// mod3/index.ts
import { createFoo } from "mod2";

export const getFoo = () => createFoo("foo");
// mod3/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod2": "workspace:*"
  }
}

Finally, mod4 depends on mod3 and uses getFoo to create another function:

// mod4/index.ts
import { getFoo } from "mod3";

export const foo = getFoo();
// mod4/package.json
{
  ...
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    }
  },
  "dependencies": {
    "mod3": "workspace:*"
  }
}
🙁 Actual behavior

Because mod3 has an invalid index.d.ts, mod4 fails compilation when doing a lib check of mod3's type declaration files. This is the invalid declaration file from mod3:

export declare const getFoo: () => import("mod1").Foo;
//# sourceMappingURL=index.d.ts.map
🙂 Expected behavior

For the behavior from previous versions of TypeScript to be maintained: Since mod2 re-exports mod1s types, and since mod3 depends on mod2, compiling mod3 should produce this:

export declare const getFoo: () => import("mod2").Foo;
//# sourceMappingURL=index.d.ts.map
Additional information about the issue

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

リンクされた path-rewrite-bug pnpm モノレポから始め、issue に記載されたバージョンを使って mod1 から mod4 までのパッケージをビルドします。mod3 の生成された dist/index.d.ts を調べ、その宣言が mod1 ではなく mod2 経由で Foo をインポートしているか確認します。生成された宣言が期待される出力と一致し、宣言ファイルを確認した状態で mod4 のコンパイルが成功すれば完了です。

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

評価

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

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

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