microsoft / microsoft/TypeScript
Readonly properties type narrowing doesn't flow into inner function scopes
オープン
まだ誰も着手していません。
Domain: check: Control Flow
Experience Enhancement
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.3.0-dev.20190105
Search Terms: Readonly, strictNullChecks, optional, inner function
Code
Using strictNullChecks: true:
interface Thing {
foo?: (a: number) => boolean;
}
const t: Readonly<Thing> = {
foo: (a) => true,
};
if (t.foo !== undefined) {
const bar = () => {
t.foo(5);
}
}
Expected behavior:
👍 Compile
Actual behavior:
On the expression t.foo(5); the following error:
Cannot invoke an object which is possibly 'undefined'.
(property) foo?: ((a: number) => boolean) | undefined
Related Issues:
- Possibly a duplicate https://github.com/Microsoft/TypeScript/issues/22137, but I wasn't sure.
- Following the theory of this issue, this should be seen as a bug: https://github.com/Microsoft/TypeScript/issues/10927.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された TypeScript の再現コードとその Playground リンクから始め、arrow function 内の readonly のオプショナルプロパティに対する制御フローの narrowing に焦点を当ててください。報告されたエラーを確認し、関連する issue と動作を比較してください。完了の条件は、undefined の呼び出しを誤って許可せずに例がコンパイルできることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 42/100