Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
elizabethdinella opened this issue Aug 10, 2018 · 0 comments · Fixed by #27031
Closed
Assignees
Labels
Bug A bug in TypeScript

Comments

@elizabethdinella
Copy link
Contributor

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants