Open
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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