Skip to content

Bug: "Convert to async function" refactor generates invalid code with imported functions #39858

@jeremy-deutsch

Description

@jeremy-deutsch

TypeScript Version: 3.9.2, 4.0 beta

Search Terms:
Convert to async function, refactor, quick fix
Code

import { identity } from "underscore"

function fetchZero() {
  return Promise.resolve(0).then(identity);
}

Expected behavior:

Running the "Convert to async function" Quick Fix on fetchZero should produce

async function fetchZero() {
  const value=await Promise.resolve(0);
  return identity(value);
}

(or something similar). This is the behavior if identity is defined in the same file, with a first parameter named value.

Actual behavior:

Running the "Convert to async function" Quick Fix on fetchZero produces

async function fetchZero() {
  const identity=await Promise.resolve(0);
return identity(identity);
}

which produces a TypeError with identity(identity). This is the behavior if identity is imported.

Playground Link:
https://www.typescriptlang.org/play/index.html?ssl=5&ssc=2&pln=1&pc=1#code/JYWwDg9gTgLgBAbzsAJgUwHY2DAnnAXzgDMoIQ4AiAVw3SgGcBjaNSgKHeNqewgxJoYTABYAtNGQAUASkTs4cKEOpQBABTIhgDNADplDCABsAbmikAGGXpgjMU1Jmx4ZAbnYEgA

Related Issues:
#39589 is another issue with the "Convert to async function" Quick Fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbol

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions