microsoft / microsoft/TypeScript
Optional arguments in JSDoc types may be moved to TypeScript types quickfix
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.4.3
80004jsdoc quickfix optional
Code
With Closure Compiler, you mark a function parameter optional by adding an = after its type (reference):
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a, b) {
if (b) return a + b;
return a;
}
TypeScript offers a quickfix to convert these jsdoc annotations to TypeScript types:

Expected behavior:
The b parameter should be optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b?: string): string {
if (b) return a + b;
return a;
}
Actual behavior:
The b parameter is required but has type string | optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b: string | undefined): string {
if (b) return a + b;
return a;
}
This means that all calls of the function which don't specify b will be flagged as errors.
Playground Link: link, though quickfixes are not available there
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された foo 関数を使って JSDoc-to-TypeScript 型の quickfix を再現し、生成されたパラメーター型を期待されるオプショナルパラメーターと比較します。quickfix のエントリーポイントを追跡し、b を省略した呼び出しが受け入れられる一方で、生成される戻り値の型は string のままであることを示す回帰テストカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100