microsoft / microsoft/TypeScript
Object is possibly undefined after undefined check on readonly property
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.7.4, 3.9.2
Search Terms:
Object is possibly undefined
undefined readonly callback
Code
class Test {
private readonly testProperty?: { value: number };
public constructor(testProperty: { value: number }) {
this.testProperty = testProperty;
}
public method() {
if (this.testProperty) {
Promise.resolve().then(() => this.testProperty.value); //Object is possibly undefined
}
}
}
Expected behavior:
testProperty should not be resolved as possibly undefined as this is not possible in this scenario as the property has already been checked and it is marked as readonly.
Actual behavior:
testProperty is possibly undefined, requiring another undefined check.
Related Issues:
Similar issues but these i understand why TypeScript would report an error, in my case the property is readonly so it seems like a bug to me.
https://github.com/microsoft/TypeScript/issues/38053
https://github.com/microsoft/TypeScript/issues/11498
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている Playground の再現例から始め、関連する issue #38053 と #11498 に記載された挙動を比較してください。Promise コールバック内の readonly optional property に対する型チェックを追跡してください。完了の条件は、提示された例で「possibly undefined」が報告されなくなるか、期待される挙動が別の形で解決されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100