镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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);
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