microsoft / microsoft/TypeScript
False-positive `unintentional comparison` error with closures
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
### 🔎 Search Terms
unintentinal, comparison, 2367, overlap
### 🕗 Version & Regression Information
- typescript: `v7.0.2`
- node: `v24.14.1`
- pnpm: `v12.3.4`
### ⏯ Playground Link
_No response_
### 💻 Code
```ts
let n: "a" | "b" = "a";
const updateN = () => {
n = "b";
};
// This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap. [2367]
if (n === "b") {}
updateN();
// This comparison appears to be unintentional because the types '"a"' and '"b"' have no overlap. [2367]
if (n === "b") {}
n = "b";
// No error
if (n === "b") {}
```
### 🙁 Actual behavior
If a variable of type `"a" | "b"` is changed in a function with closure, the LSP fails to catch the change, and assumes that it was never changed.
### 🙂 Expected behavior
No error warning, since code works as expected
### Additional information about the issue
_No response_
コントリビューションガイド
調査の方向性
TypeScript v7.0.2 で issue の closure の例を再現し、diagnostic 2367 を出力する type-checker の経路を調査します。updateN をまたいで control-flow narrowing がどのように処理されるかを追跡し、両方の比較を対象とする回帰テストを追加します。closure 呼び出し後の比較で誤検知の警告が発生せず、同時に例が引き続き正しくチェックされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100