microsoft / microsoft/TypeScript
noImplicitReturnType [Suggestion]
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
We have noImplicitReturns which is great and helps tick up silly mistakes but it woud great to have noImplicitReturnType as well.
So what would noImplicitReturnType do?
Currently we can write a function like so:
function life () {
return 42;
}
let x = life(); // Number
So all is great, TypeScript works out the return type nicely for us.
function life (x: boolean) {
if (x) {
return 'hi';
} else {
return 42;
}
}
let y = life(true); // Number / String
This is where things start to go a little crazy. TypeScript records y as of type number | string which is of course acurate. But what if i wanted this function to only return strings?
We already have support for that with limited modifications
function life (x: boolean): string {
if (x) {
return 'hi';
} else {
return 42; // Type '42' is not assignable to type 'string'.
}
}
let y = life(true);
And as a result TypeScript nicly throws an error.
So my suggestion is that in much the same way as with noImplicitAny and let enforcing strict typeing an argument is added in the form of noImplicitReturnType which for my first example (only a single return) wouldn't have any effect but for the second would throw an error instead of typing the function as number | string
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、既存の noImplicitReturns および noImplicitAny オプションと、例で説明されている提案中の noImplicitReturnType の動作を比較します。推論された戻り値の型が union である関数に対して意図されている診断を特定し、新しいコンパイラオプションについて何をもって完了とするかを定義します。この issue ではファイルやテストは指定されていません。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100