-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [promise-function-async] flag non-async
functions returning unions with non-Promise
types
#6329
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
I wonder if there's a heuristic we can apply here to avoid the need for an option. Like "if the function has an explicit or contextual return type that is not |
If it has an explicit type that includes non-promises, that would make sense, sure. The real issue, I suppose, is when the implicit type includes a union with non-promises, it should still be flagged, imo. |
When we return a union containing a promise from a function implicitly, it's often a mistake. This commit makes it so if the return type is explicit, any `Promise` in the return type (whether it's part of a union or not) will flag the function. If it is intentional, make the return type explicit. Fixes typescript-eslint#6329
@bradzacher I put up a PR implementing the heuristic you suggested. Take a look and let me know what you think, or of any suggestions. |
async
functions returning unions with non-Promise
types
When we return a union containing a promise from a function implicitly, it's often a mistake. This commit makes it so if the return type is explicit, any `Promise` in the return type (whether it's part of a union or not) will flag the function. If it is intentional, make the return type explicit. Fixes typescript-eslint#6329
When we return a union containing a promise from a function implicitly, it's often a mistake. This commit makes it so if the return type is explicit, any `Promise` in the return type (whether it's part of a union or not) will flag the function. If it is intentional, make the return type explicit. Fixes typescript-eslint#6329
…mplicit return types (#6330) * [promise-function-async] Only allow unions in explicit return types When we return a union containing a promise from a function implicitly, it's often a mistake. This commit makes it so if the return type is explicit, any `Promise` in the return type (whether it's part of a union or not) will flag the function. If it is intentional, make the return type explicit. Fixes #6329 * Refrain from renaming the type-util, instead add an optional fourth param.
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
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
Pass
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).
The text was updated successfully, but these errors were encountered: