microsoft / microsoft/TypeScript
TSC should not error on valid subpath specifier syntax (TS2877)
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- PR merge metrics
- PR metrics pending
Description
### 🔎 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).
Contributor guide
Research direction
Start with the linked Playground reproduction and the repro repository, using the listed compiler options and the TS2877 diagnostic as entry points. Trace why the '#alice.ts' subpath import is treated as a non-rewritable input file. Done means this valid specifier no longer produces TS2877 while the reported relative-path behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100