microsoft / microsoft/TypeScript

bug: error message says 0n is truthy

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

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

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

説明

🔎 Search Terms

falsey, truthy, bigint, PseudoBigInt, TS Error 2872, TS Error 2873, unnecessary condition, constant condition

🕗 Version & Regression Information
⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&ts=5.7.0-dev.20241022#code/JYMwBAFADAdglGA3mFAoAvkA

💻 Code

0n is falsy.

if (0n) {
  // won't happen
}
🙁 Actual behavior

TS 2872: This kind of expression is always truthy.

🙂 Expected behavior

TS 2873: This kind of expression is always falsy.

Additional information about the issue

I am presuming that this is due to this function, which always reports BigIntLiteral as PredicateSemantics.Always, rather than checking for 0n.

https://github.com/microsoft/TypeScript/blob/c07da583afbfbb68930448b781832c74b3f713e6/src/compiler/checker.ts#L44498-L44532

Looks like this has been present since the always-truthy/always-falsey check was initially created: https://github.com/microsoft/TypeScript/pull/59217/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R44293

I'd be happy to drop a PR if this is accepted and that's the issue.

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

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

はじめの一歩

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

調査の方向性

src/compiler/checker.ts のリンクされた述語セマンティクス関数から開始し、提供された TypeScript Playground リンクで動作を再現してください。0n が常に falsy として分類され、診断が TS 2872 から TS 2873 に変わることを確認し、コンパイラーの既存のテスト構造を使ってカバレッジを追加してください。

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

評価

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

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

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