-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-floating-promises] flag .map(async)
result
#5958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Technically speaking, this is not a floating promise, because the return type of This is the same if you wrap the promise in anything: function getObj(p: Promise<any>) {
return { p };
}
getObj(Promise.resolve(1));
Let's see if others have ideas; I don't think there's a great heuristic to catch these cases unless we special-case object types and array types. |
I think this would be a pretty good addition to the lint rule! We'd have to put this behind an option (default false for now) to avoid a breaking change, but i'd hazard a guess that we could turn it on by default eventually. Would be good to audit some codebases to be sure. WDYT @Josh-Cena? |
Does that mean we special-case array types and object types? I was talking with @JoshuaKGoldberg and he seemed to dislike special-casing. |
Object types - no I don't think so because there is no construct to handle them natively. So our rule would report and then someone would have to refactor their code completely to extract and await the promise. But array types are different to object types - they have the native promise methods to await them. This means there's no difficult code change to make - as I mentioned the simplest would be To me at least handling the array case isn't a special case - instead it's just a natural extension to the rule. |
I'm on the fence here and fine either way. It feels like we're entering "there's no perfect answer" territory. The case of array types being special & built-in makes sense to me but I wouldn't mind either way. 🤷 |
Is this the issue causing the following code to be marked incorrectly as okay? Is: |
.map(async)
result
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=4.8.4&sourceType=module&code=MYewdgzgLgBAJgQygmBeGBtA5FAptLAXQG4AoUxZAOgFsEAHACgQgE8xgZGBKNAPhgBvUjBgIA7ggCWsMLnEwACgCcQNKRFyNGAfWX4ANDH0ArXqgGaoAFSk1cIAK5RGpowEYADN+7cyAXz9SIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aRAR1ko9oEMA7v0r50URNGgB7aJAA04bHiKlkFanQbM2TabQBm8af3zMA5rWIyAtpWQpxkSTLlKAviHdA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA
Repro Code
ESLint Config
tsconfig
Expected Result
Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the
void
operator.Actual Result
No eslint error, but ERR_UNHANDLED_REJECTION when running
Additional Info
No response
Versions
@typescript-eslint/eslint-plugin
5.42.1
@typescript-eslint/parser
5.42.1
TypeScript
4.8.4
ESLint
8.15.0
node
web
The text was updated successfully, but these errors were encountered: