Skip to content

await is missing after autofix convert to an async function #39589

@Bnaya

Description

@Bnaya

TypeScript Version: 3.9.6, 4 beta

Search Terms:
autofix convent to async function
Code

// The auto fix turns this code:
function stripAnsiOnRejection(p: Promise<unknown>) {
    return p.catch((error: Error) => {
        error.message = stripAnsi(error.message);
        return Promise.reject(error);
    });
}

// Into 
async function stripAnsiOnRejection(p: Promise<unknown>) {
    try {
        return p;
    }
    catch (error) {
        error.message = stripAnsi(error.message);
        return Promise.reject(error);
    }
}

Expected behavior:
The return line should be return await p

Actual behavior:
The return line is return p

Playground Link: https://www.typescriptlang.org/play/?ts=4.0.0-beta&ssl=6&ssc=2&pln=1&pc=1#code/GYVwdgxgLglg9mABAZygJxgBwIJmTAeTACUBTAK1OnjAApMAuRABTTgFsZlSAecAazBwA7mAB8ASkQBvALAAoREsRpSUEGiSYAdBACGUCAAtatUmjZomAUQtw0UgLxiZC5e8TnL29qWTI9AHNSREcUdCxcfDM7NB8-AOCJAG43DyVVdU0WNk5ubVVKaBjLFLSlAF8y+QqgA

Related Issues: #31897

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions