Skip to content

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

Closed
@elizabethdinella

Description

@elizabethdinella

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);

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @RyanCavanaugh@elizabethdinella@uniqueiniquity

    Issue actions

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