microsoft / microsoft/TypeScript
Type guard/Equality narrowing doesn't work on "any"
オープン
まだ誰も着手していません。
Domain: check: Control Flow
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
type guard equality narrowing strict equal equality
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I found earlier issues (https://github.com/microsoft/TypeScript/pull/9407 and the PR that added this feature https://github.com/microsoft/TypeScript/pull/9407)
⏯ Playground Link
💻 Code
function bar( arg: any ) {
if ( arg === null ) {
return arg;
}
if ( arg === false ) {
return arg;
}
}
🙁 Actual behavior
arg should be null/false inside the if conditions
🙂 Expected behavior
arg is any
The docs say this should work https://www.typescriptlang.org/docs/handbook/2/narrowing.html
When using unknown instead of any it works perfectly fine. I think adjusting this, so it works for any too, isn't too far fetched.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground で narrowing の動作を再現し、unknown について文書化されている動作と比較してください。any の equality narrowing における type-checker の経路を追跡し、その後、null と false が期待どおりに絞り込まれることを示す回帰テストのカバレッジを追加して、関連する compiler テストを実行してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100