microsoft / microsoft/TypeScript

Enable `--allowImportingTsExtensions` by default

オープン
#62,342 コメント 7 件 リアクション 15 件 担当者 0 名 GitHub で見る

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

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

説明

### Acknowledgement

- [x] I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

### Comment

This is a pitch for another configuration change to go into TypeScript 6.0.

## Background

TypeScript initially introduced a convention-based build step that converts `*.ts` source files into `*.js` executable files. To avoid needing to rewrite extensions during the build step, import specifiers in `*.ts` files could only reference other TypeScript files via `*.js` extensions. The compiler errored if you asked for a `*.ts` file. This static error was initially useful because it prevented the user from writing code that would later fail at runtime.

Over time, the world changed. Runtimes such as Deno, Bun, and Node (and more\!) introduced built-in TypeScript support that could handle `*.ts` files directly. There was no need to have an internal concept of renaming the file to use a `*.js` extension. In fact, runtimes such as Deno and Node actively prevent the old convention of allowing folk to use `*.js` names to import a `*.ts` file.

Outside the runtimes, all modern tooling now understands how to resolve references to `*.ts` files. That includes widely-used bundlers such as Vite, ESBuild, Rollup, Turbopack, webpack, Parcel, RsPack. And it includes widely-used runtime loaders such as tsx and ts-node. Support for importing `*.ts` extensions is close to being universal.

In the browsers, ES Module resolution of relative imports is highly literal. You directly get what you ask for with no extension-guessing. Purists using a simplistic type-stripping compiler (ala [`ts-blank-space`](https://bloomberg.github.io/ts-blank-space/)) need to use `*.ts` imports to be web-compatible whilst avoiding the complexities of extension rewriting.

The conclusion is that the world has flipped and importing `*.ts` has now become the most compatible choice.

## Motivation

The set of default configuration changes being [pitched for TypeScript 6.0](https://github.com/microsoft/TypeScript/issues/54500) are excellent. They almost result in TypeScript being usable out-of-the-box with Node's built-in TypeScript support\! The only true blocker remaining is `--allowImportingTsExtensions.`

Whilst it's true that Node users will benefit from [other options](https://nodejs.org/api/typescript.html#type-stripping) such as `verbatimModuleSyntax`, `rewriteRelativeImportExtensions`, and `module: nodenext` rather than `esnext`, those could be considered DX enhancements. Whereas `*.ts` support is non-negotiable.

The minimum goal is to eliminate the verbosity of needing to specify this flag. A very similar but slightly more ambitious goal this contributes towards is to make Node usage frictionless.

## Proposal

TypeScript 6.0 will assume that `--allowImportingTsExtensions` is on, unless explicitly disabled.

It seems unlikely this will be a breaking change so I can't think of any more advice to give on adoption.

### Fallback Proposal

Depending on how the rest of TypeScript 6.0 config changes go, a next-best option would be to have implied defaults. For instance, if `moduleResolution: bundler` were the default, and that implied `--allowImportingTsExtensions`, then the goal of out-of-the-box Node usage would still be achieved.

Likewise if only `module: nodenext` implied `--allowImportingTsExtensions` that would still be helpful in reducing config fatigue, but would only hit the full goal if `module: nodenext` became the default.

## Open Questions

### How should tooling handle detection?

Potentially some tooling is already gating their own acceptance of `*.ts` by reaching into `tsconfig` and inspecting this flag. I'd suggest the way forward is to match TypeScript: to flip the default and continue to inspect `tsconfig` for the negative case.

So there may be some impact, but it is mostly business as usual for tooling to follow upstream TypeScript choices.

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

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

はじめの一歩

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

調査の方向性

この issue にはファイルもテストも記載されていません。まず、TypeScript が --allowImportingTsExtensions オプションとそのデフォルト設定をどのように扱うかを追跡し、次に issue でリンクされている TypeScript 6.0 の設定案を確認してください。デフォルトの動作と明示的な opt-out が定義され、影響を受けるツールの動作と互換性に関する問題が解決されれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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