microsoft / microsoft/TypeScript
Destructuring assignment with computed property name does not help narrow types as intended.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
### 🔎 Search Terms
"destructuring assignment", "computed property name", "type narrowing"
### 🕗 Version & Regression Information
Happen to all existing version in typescript playground.
### ⏯ Playground Link
https://tsplay.dev/w1eElw
### 💻 Code
```ts
declare let obj: Record
declare let cond: boolean;
declare let key: string;
let result: string | null = null;
if (cond) {
({ [key]: result } = obj);
result;
// ^?
}
if (cond) {
({ 'key': result } = obj);
result;
// ^?
}
```
### 🙁 Actual behavior
Type narrowing did not happen to the assignee variable `result` after the assignment `({ [key]: result } = obj);`.
### 🙂 Expected behavior
Expecting the assignment `({ [key]: result } = obj);` will narrow the assignee variable `result` to non-null.
### Additional information about the issue
_No response_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、computed-property の分割代入と literal-property の代入の後における result の推論された型を比較します。関係する型の絞り込みの挙動を追跡し、完了した変更によって両方の例で期待される non-null の絞り込みが維持されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100