Skip to content

Enhancement: [promise-function-async] flag non-async functions returning unions with non-Promise types #6329

Closed
@ericbf

Description

@ericbf

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/promise-function-async/

Description

I am finding cases in my code where it accidentally is returning undefined or some other guard type (null, etc) from a function that we expected to be async, but the rule promise-function-async is not flagging those as I expected it to (allowing us to catch those mistakes).

Please add an option to promise-function-async that will allow it to flag any function that returns promises at all, either as the main return type, or as a union containing promises.

Fail

function getSomething(id?: string) {
    if (!id) {
        return undefined
    }

    return db.getByID(id)
}

Pass

async function getSomething(id?: string) {
    if (!id) {
        return undefined
    }

    return db.getByID(id)
}

Additional Info

There is an issue for the opposite of my request, #1005. I’d like that feature back (probably behind an option, seeing as it was designated as a bug before).

Metadata

Metadata

Assignees

Labels

enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions