Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: [no-misused-promises] should include checks around synchronous using statements and Symbol.dispose. #10357

Open
@kirkwaiblinger

Description

@kirkwaiblinger

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/no-misused-promises/

Description

I would like the rule to add a few checks for misused promises involved in explicit resource management code. This is split out from #10208 (comment)

Fail

// rule does not inspect variable for misused promise-returning functions
const a = {
    async [Symbol.dispose]() {}
} 
const b: Disposable = a;
//                    ~ <-- expected report here.


// `using` statement without explicit type
using c = {
    async [Symbol.dispose]() {}
//  ~~~~~~~~~~~~~~~~~~~~~~ <-- expected report here.
};

// combination of both of the above
const d = {
    async [Symbol.dispose]() {}
} 
using e = d;
//        ~ <-- expected report here.

Pass

// just a sync disposable
using a = {
    [Symbol.dispose]() {}
}

// proper use of await using (note `Symbol.asyncDispose`)
await using b = {
    async [Symbol.asyncDispose]() {}
}

Additional Info

Note that the upcoming strict-void-return aims to be a superset of no-misused-promises, so perhaps this check will make sense to add there also, see #9707

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions