microsoft / microsoft/TypeScript

TSC should not error on valid subpath specifier syntax (TS2877)

未关闭
#63,129 14 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

### 🔎 Search Terms

TS2877

### 🕗 Version & Regression Information

This changed between versions 5.6 and 5.7 (best guess; 5.7 introduced `rewriteRelativeImportExtensions`).

### ⏯ Playground Link

https://www.typescriptlang.org/play/?rewriteRelativeImportExtensions=true&resolvePackageJsonExports=true&resolvePackageJsonImports=true&noUncheckedSideEffectImports=true&allowArbitraryExtensions=true&allowImportingTsExtensions=true#code/PTAEEkFsAcHsCcAuBnUAbAlgawKakQBY7J4DGAhgK4mgAqAygEwAcA7KwDQBQIoA7kQB2oDMIBm5UonxF4OAOSpBsQqIDm-eLEEbyAI1iVphHJAB0XHmAACKALQ4AHtBxSH8LfABcMjKj6GaAAmoHIAjpQYcqDkoNCSWORqOGYAVsja+LChxLBoAG44XBgwCNIARADE5JikKSjlANxcQA

### 💻 Code

```ts
// Imports like these cause TS2877,
// when in fact there's nothing wrong about them.
import "#alice.ts";
```

### 🙁 Actual behavior

```txt
error TS2877: This import uses a '.ts' extension to resolve to an input TypeScript file, but will not be rewritten during emit because it is not a relative path.
```

### 🙂 Expected behavior

Don't error.

### Additional information about the issue

Specifiers aren't paths. Especially subpath imports and exports allow for almost arbitrary string rewriting. The compiler is blatantly wrong about this.

Edit: I've created a [repro repo](https://github.com/valler/repro-repo-for-ms-typescript-issue-63129).

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 Playground 复现和 repro repository 开始,以列出的编译器选项和诊断 TS2877 作为切入点。追踪为什么子路径导入 '#alice.ts' 会被视为不可重写的输入文件。完成的标准是:这个有效的 specifier 不再产生 TS2877,同时报告的相对路径行为保持不变。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
64/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。