microsoft / microsoft/TypeScript

Option to copy custom types to outDir

オープン
#35,296 コメント 4 件 リアクション 17 件 担当者 0 名 GitHub で見る

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

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

説明

Search Terms

declaration files, .d.ts, ergonomics, distributable package, library, compiler option

Suggestion

I would like tsc to include an option that enables copying .d.ts files from my project's source tree into the configured outDir.

Use Cases

I maintain a distributable library that is often used as a dependency of other packages. As often as I can, I depend on @type/* packages and the core type libraries to express the types in the platforms that my library supports.

However, there are cases where these sources do not reflect the ground truth of my supported platforms (for example, old browsers w/ proprietary APIs, or experimental/unstable/nascent web platform features). In these cases, it isn't suitable to upstream my custom types to another package, and even if it was, the latency involved in waiting for upstream contributions to be accepted and published is not a good reason to block a release of my library.

In cases like these, I tend to express the types in .d.ts files in my source tree. However, per https://github.com/Microsoft/TypeScript/issues/5112, tsc does not copy these files to my configured outDir as a matter of principle. This means that I have to complicate my build with an additional copy step in order to produce a comprehensive, publishable artifact. Meanwhile, it seems like tsc could make my life a lot simpler by copying over these files on my behalf.

Examples

This could manifest in a lot of ways, but a strawperson would be to add a compiler flag. Call it --include-custom-type-declarations (or any suitable name).

If tsc is invoked with this flag set to true, then tsc will include all .d.ts declarations in the source tree among the artifacts generated in the outDir.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

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

はじめの一歩

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

調査の方向性

まず、issue に記載されている既存の動作を基準として、tsc がソース .d.ts ファイルと設定された outDir をどのように扱うかを調査します。オプションの対象範囲とコピー動作を定義し、その後、既存のコンパイラーの動作を変更せずに、カスタム宣言が配布可能な出力に含まれることを確認します。

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

評価

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

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

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