microsoft / microsoft/TypeScript
rewriteRelativeImportExtensions: tsc doesn't rewrite extensions in emitted declaration files
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 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!
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用启用 rewriteRelativeImportExtensions 和 declaration 的 index.ts 与 tsconfig.json 重现该问题,然后跟踪 tsc 针对该选项的 declaration emit 路径。完成标准是,生成的 .d.ts 将 './file.ts' 一致地重写为 './file.js',与 JavaScript 输出保持一致,并覆盖报告的案例。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100