microsoft / microsoft/TypeScript

rewriteRelativeImportExtensions: tsc doesn't rewrite extensions in emitted declaration files

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

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

Experience Enhancement Help Wanted Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

🔎 Search Terms

"rewriteRelativeImportExtensions", "extensions", "declaration", ".d.ts"

🕗 Version & Regression Information
  • This is the behavior in every version I tried (even in the next 5.8.0), and I reviewed the FAQ for entries about "rewriteRelativeImportExtensions"
⏯ Playground Link

No response

💻 Code

In an index.ts file:

export * from './file.ts';

then build it with tsc and "rewriteRelativeImportExtensions": true & "declaration": true in the compilerOptions of your tsconfig.json

🙁 Actual behavior

Built files content:
In the JS file, index.js, the extension is rewritten to .js:

export * from './file.js';

In the declaration file, index.d.ts, the extension is not rewritten to .js:

export * from './file.ts';
🙂 Expected behavior

In the declaration file, the extension should be rewritten to .js too:

export * from './file.js';
Additional information about the issue

It occurs in the current TS 5.7.3 and in the next version (5.8.0-dev.20250123 at this time). Even if TS correctly interprets .d.ts files with .ts extensions in import/export, it's not the case of the IDE I use, PhpStorm. It can't provide a real code assistance with these declaration files.
In fact, I don't really know if it's a feature, a bug or an oversight in tsc, or if rewriteRelativeImportExtensions is just too new to be completely supported by all IDEs! Let me know!

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

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

はじめの一歩

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

調査の方向性

rewriteRelativeImportExtensions と declaration を有効にした tsconfig.json と index.ts で問題を再現し、その後、このオプションに対する tsc の declaration emit パスを追跡します。生成された .d.ts が JavaScript の出力と一貫して './file.ts' を './file.js' に書き換え、報告されたケースのカバレッジがあることが完了条件です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

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

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