microsoft / microsoft/TypeScript

`strictNullChecks` short-circuits the subsequent type checks

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

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

Needs Proposal Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

hello, I encounter a strange bug when I use strictNullChecks: true, and here is an example:

interface A {
  a: number;
}
const list: A[] = [];
list[0] ??= {};  // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {};  // the type checking not work !
list[0] = list[0] || {};  // the type checking not work !
🔎 Search Terms
🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

It seems the type checking works after I close the strictNullChecks options
Playground link with relevant code

💻 Code
interface A {
  a: number;
}
const list: A[] = [];
list[0] ??= {};  // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {};  // the type checking not work !
list[0] = list[0] || {};  // the type checking not work !
🙁 Actual behavior

list[0] = list[0] ?? {}; doens't throw any errors

🙂 Expected behavior

I expect that list[0] = list[0] ?? {}; should throw an error

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

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

はじめの一歩

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

調査の方向性

リンク先の TypeScript Playground から始め、strictNullChecks を有効にして例を再現し、??= とそれに続く ?? および || の代入を比較してください。これらの代入形式に対する型チェックの経路を追跡し、不完全なオブジェクトを代入すると不足しているプロパティのエラーが報告されることを示す回帰テストを追加または更新してください。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

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

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