Microsoft/TypeScript

Destructuring assignment with computed property name does not help narrow types as intended.

Open

#62,401 opened on Sep 5, 2025

View on GitHub
ย (4 comments)ย (0 reactions)ย (0 assignees)TypeScriptย (48,455 stars)ย (6,726 forks)batch import
Domain: check: Control FlowHelp WantedPossible Improvement

Description

๐Ÿ”Ž 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

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

Contributor guide

Destructuring assignment with computed property name does not help narrow types as intended. ยท Microsoft/TypeScript#62401 | Good First Issue