Non-null assertion should work on possibly-uninitialized auto-typed `let` variables

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

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

評価

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

調査の方向性

リンクされている TypeScript Playground と foobarbaz の例から始め、続いて初期化されていない let に対するコンパイラの推論と non-null assertion の処理を追跡します。foo! が implicit-any エラーを生成せずに string 型として受け入れられ、一方で bar は引き続き string | undefined と推論されれば完了です。

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

説明

Experience Enhancement Help Wanted Suggestion

Bug Report

🔎 Search Terms

non-null postfix bang implicit any

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

This is the link

💻 Code
let foo;
if (Math.random() > 0.5) {
  foo = "hello";
}
// bar: string | undefined, seems fine
let bar = foo;
/* -- pretend I know foo is defined for other reasons -- */
// Error, foo is implicitly any
let baz = foo!;
🙁 Actual behavior

Implicit any on foo!

🙂 Expected behavior

Since the inferred type of foo (as seen in bar) is string | undefined, foo! should trivially have the type string

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

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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