Typescript: Typescript async conversion should watch out for const

Created on 16 Nov 2020  路  4Comments  路  Source: microsoft/TypeScript

TS Template added by @mjbvz

TypeScript Version: 4.2.0-dev.20201116

Search Terms

  • quick fix
  • suggestion
  • convert to async


    getCommands(filterUnderscoreCommands: boolean = false): Promise<string[]> {
        this._logService.trace('ExtHostCommands#getCommands', filterUnderscoreCommands);

        return this._proxy.$getCommands().then(result => {
            if (filterUnderscoreCommands) {
                result = result.filter(command => command[0] !== '_');
            }
            return result;
        });
    }

recording (1)

Bug Refactorings

Most helpful comment

Minimal repo:

function getCommands(): Promise<any> {
    return Promise.resolve(1).then(result => {
        result = result + 2;
    });
}

results in:

async function getCommands(): Promise<any> {
    const result = await Promise.resolve(1);
    result = result + 2;
}

All 4 comments

Minimal repo:

function getCommands(): Promise<any> {
    return Promise.resolve(1).then(result => {
        result = result + 2;
    });
}

results in:

async function getCommands(): Promise<any> {
    const result = await Promise.resolve(1);
    result = result + 2;
}

What the expected result for this issue?

/cc @mjbvz

To use let instead.

@joaomoreno Like so?

ts async function getCommands(): Promise<any> { let result = await Promise.resolve(1); result = result + 2; }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

remojansen picture remojansen  路  3Comments

dlaberge picture dlaberge  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments