Microsoft/TypeScript
GitHub ã§èŠãDestructuring assignment with computed property name does not help narrow types as intended.
Open
#62,401 opened on 2025幎9æ5æ¥
Domain: check: Control FlowHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
"destructuring assignment", "computed property name", "type narrowing"
ð Version & Regression Information
Happen to all existing version in typescript playground.
⯠Playground Link
ð» Code
declare let obj: Record<string, string>
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