Skip to content

Async / Await Refactoring - Catch Block Parameter are not checked for collisions #26376

Description

Search Terms:
Async, Await, Refactoring, Code Fix,

Code

function f() {
	return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); 
}

Expected behavior:
The refactor generates the following code with a unique catch parameter.

async function f() {
	let x_1: string | number;
    try {
        const x = await Promise.resolve();
        x_1 = 1;
    }
    catch (x_2) {
        x_1 = "a";
    }
    return !!x_1; 
}

Actual behavior:
The refactor generates the following code with a conflicting catch parameter. "a" is not assigned to the correct x_1.

async function f() {
	let x_1: string | number;
    try {
        const x = await Promise.resolve();
        x_1 = 1;
    }
    catch (x_1) {
        x_1 = "a";
    }
    return !!x_1; 
}

Playground Link:

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions