microsoft / microsoft/TypeScript

Preserve interfaces in generated declaration files for augmentation

オープン
#42,853 コメント 7 件 リアクション 2 件 担当者 1 名 GitHub で見る

@weswigham がすでに取り組んでいます。

2021年2月18日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Suggestion

2023 Updat

We investigated this, and turns out its easy to workaround, just extract function's type into standalone type declaration. So its low priority for us now.

🔍 Search Terms

Stop emitting never for empty interfaces from declaration

✅ Viability 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, new syntax sugar for JS, etc.)
  • [ X This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Make TypeScript compiler preserve references to original Interfaces. (or at very least add an option for this!)

📃 Motivating Example

Playgroud link

export interface InterfaceToAugment {

}

export default <T extends keyof InterfaceToAugment>(key: T, value: InterfaceToAugment[T]) => { };

After we run tsc (with declaration: true of course) we'll see our .d.ts file:

export interface InterfaceToAugment {
}
declare const _default: <T extends never>(key: T, value: InterfaceToAugment[T]) => void;
export default _default;

As you can see here, declaration file making this interface absolutely useless., but I wanted to make this function to pick real keys of this interface.

Is there any workaround for this?

💻 Use Cases

Module Augmentation for library consumer

declare module "this-lib" {
  interface InterfaceToAugment {
    myCustomKey: 5
  }
}

Please, correct me if I missed something

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

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

はじめの一歩

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

評価

この issue はまだ評価されていません。

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

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