microsoft / microsoft/TypeScript
Intellisense: optional parameters are too verbose (bar? number | undefined)
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
optional parameters intellisense
Suggestion
The intellisense for optional parameters is too verbose:
an optional function parameter defined e.g. like this
function foo (bar?: number) {
}
gets resolved in the intellisense as
function foo(bar?: number | undefined): void
The optional nature of the bar parameter is indicated two times, once with number | undefined type and once with the question mark sign bar?:
Proposal:
Just use question mark in intellisense signatures
function foo(bar?: number): void
Use Cases
The | undefined bloats the length of the function signatures generated by the intellisense. This
makes the signatures too long leading to loss of important information in the intellisense in longer methods (e.g. the return types are shortened...)
Examples
Here is an example:
class IotFileClient {
public async GetFiles(
entityid: string,
params?: {
offset?: number;
limit?: number;
count?: boolean;
order?: string;
filter?: string;
}
): Promise<IotFileModels.IFile> {
return {name: "test"};
}
}
This produces the intellisense output like this:
(method) IotFileClient.GetFiles(entityid: string, params?: {
offset?: number | undefined;
limit?: number | undefined;
count?: boolean | undefined;
order?: string | undefined;
filter?: string | undefined;
} | undefined): Promise<...>
Using only ?: would reduce the verbosity and leave much more room for the important information e.g. for the return values:
(method) IotFileClient.GetFiles(entityid: string, params?: {
offset?: number;
limit?: number;
count?: boolean;
order?: string;
filter?: string;
}): Promise<IotFileModels.IFile>
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 番号を参照したプルリクエストを送ります。
調査の方向性
まず、オプショナルパラメーターに対する TypeScript IntelliSense のシグネチャ表示を追跡し、issue の例を現在の出力と比較します。完了条件は、疑問符がすでにその情報を伝えている場合に、オプショナルパラメーターとプロパティで | undefined が冗長に表示されなくなり、その他のシグネチャの詳細は引き続き表示されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers, developer-experience
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100