microsoft / microsoft/TypeScript

Assertion call in optional chain should not narrow variable

オープン
#42,168 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: check: Control Flow
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 4.1.3

Search Terms: assert optional call

Expected behavior:

No narrowing of v.
Maybe an error indicating that assertion calls don't work with optional chaining.

Actual behavior:

Assertion call narrows v. If strictNullChecks is enabled, it works as expected.

Related Issues:

Code

// @strictNullChecks: false
declare const obj: {
  assert?(v: any): asserts v;
}

declare const v: boolean;
obj.assert?.(v);
v; // should not be narrowed to 'true'
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Playground Link から始め、strictNullChecks を無効にした状態でオプショナルなアサーション呼び出しの例を再現し、観測された narrowing と期待される動作を比較します。オプショナル呼び出しに対するコンパイラの制御フロー narrowing を追跡します。obj.assert?.(v) の後に v が narrowing されないか、サポートされていない組み合わせが診断されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。