microsoft / microsoft/TypeScript
Warn/error when testing a non-nullable type for null
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 2.0.0
TL;DR:
If a project is configured for strict null checks, checking a variable which is typed as non-null is nonsense and could indicate a type mismatch.
Code:
Here's a motivating example I experienced:
async function someFunc1(): Promise<string | null> {
// do some stuff and return the appropriately typed promise
}
async function someFunc2(): Promise<boolean> {
// Negating a non-null Promise is crazy talk, but here I go!
return !!someFunc1()
}
Of course what I really meant was:
async function someFunc2(): Promise<boolean> {
return !!(await someFunc1())
}
Expected behavior:
TypeScript warns that I'm effectively testing my non-null Promise for null, and points out that that's nonsense.
Actual behavior:
TypeScript happily accepted the code, which led to a bug.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にはファイル、テスト、エントリーポイントが指定されていません。まず、例で説明されている strict-null-checking の動作を確認し、TypeScript が non-nullable な式に対する null テストをどのように処理するかを追跡してください。不正なチェックによって診断が生成され、valid な nullable チェックが拒否されなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100