Skip to content

Async / Await Refactoring - Not offered on promise returning functions without an explicit return type  #26374

Description

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

Code

function f() {
	return Promise.resolve().then(res => 1); 
}

Expected behavior:
A Code Action: "Convert To Async Function" is offered.

Actual behavior:
No Code Actions are available.

This bug is due to using node.type rather than calling checker.getTypeAtLocation() in suggestionDiagnostics addConvertToAsyncFunctionDiagnostics():

const functionType = node.type ? checker.getTypeFromTypeNode(node.type) : undefined;

Changing the code to the following fixes this bug, but introduces bugs in the unused variable detection, at least when running tests.

const functionType = checker.getTypeAtLocation(node);

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