microsoft / microsoft/TypeScript
Preserve property comment and insert @default value, if provided
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
default initial initializer value preserve comment tsdoc type options option bag
Suggestion
As the title suggests, insert a @default comment to the TSDoc AST if an initializer is provided, preserving the original comment.
Use Cases
I have a default value for an option and I want the consumer of the library to know what the default value is.
Examples
interface Options {
/**
* The server host.
*/
host?: string;
port?: number;
}
function serve({ host = 'localhost', port }: Options) {
return { host, port };
}
Hovering over host in the return statement shows the following in vscode:

Not only is the TSDoc comment lost for this property, but it could furthermore be improved if @default "localhost" were added to it, seeing as that information is available in this context.
It should look like this:

Much ❤️ for the TS team!
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue ではソースファイルやテストが指定されていません。まず、TypeScript が分割代入されたパラメーターの TSDoc AST とホバー情報をどのように構築するかを追跡し、次に initializer が元のプロパティコメントを保持して @default 値を追加できる方法を確認してください。示されている host 例がコメントを保持し、出力される JavaScript を変更せずにデフォルト値を公開できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100