microsoft / microsoft/TypeScript

Emit .d.ts for type-only usage of .d.ts files in a project

オープン
#38,146 コメント 0 件 リアクション 13 件 担当者 0 名 GitHub で見る

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

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

説明

Search Terms

type only export import declaration declarations .d.ts 3.8

Suggestion

When building code has .d.ts files written and used internally, the declarations aren't emitted. This makes sense currently because .d.ts files aren't compiled. However, it causes typechecking errors when exporting content from the package for external usage, since the declaration isn't included in the compiled output.

import/export type made some initial progress for me by removing the types from the compiled JS output. but I believe it would be even more useful to re emit declarations for type only import exports. this would ensure that ambient declarations are included in the final compiled output.

My issue may be incorrect usage of declaration files, which I've only been using due to the external code generation using it. I'm not sure I explained my idea clearly, but I believe my below examples should cover it - please follow up if not.

Use Cases

I have an existing project that exports declarations generated by an external package from non-JS code. The original code doesn't need to be included, just the types for usage by external consumers. When I want to reexport those declarations, I have to manually copy them over to the build folder after since they disappear. You can see an example of this here

Examples

given directory structure

./src/index.ts
./src/generated.d.ts

and usage

// ./src/index.ts
import type Foo from './generated.d.ts'

the output structure should be

./dist/index.js
./dist/index.d.ts
./dist/generated.d.ts

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 番号を参照したプルリクエストを送ります。

調査の方向性

ソースファイルやテストは指定されていません。まず、型のみの import と .d.ts 入力に対する TypeScript の宣言出力処理を追跡し、次に要求された src-to-dist の例と比較してください。生成された出力に参照先の宣言が含まれ、JavaScript の出力が変更されなければ完了です。

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

評価

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

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

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