-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Domain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysisHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases