You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
Is your rule for a general problem or is it specific to your development style?
General, I guess :)
What does your suggested rule do?
TypeScript allows me to assign a function that returns Promise to variables or parameters that are type (...) => void. Like:
async function a() { return 0; }
type b = () => void;
const c: b = a;
and:
function d(f: b) { }
d(a);
(see spec 3.11.4)
I suggest a rule that disallows such assignments specifically for functions that return promises, so the caller of the given function does not unintentionally ignore the returned promise.
List several examples where your rule could be used
If the database call fails this will result in an unhandled promise rejection. To be safe either MyLists props has to be changed, so the given function must return a promise, or saveItem should be changed to handle the error locally.
I must admit I have no more examples right now, but for large React apps these errors can be quite hard to find and thus it might be worth a rule.
The text was updated successfully, but these errors were encountered:
A common example of people running into this issue is passing an async function as callback to Array.prototype.forEach. Since forEach doesn't care about the return value at all, there's nothing awaiting the returned promise.
Rule Suggestion
Is your rule for a general problem or is it specific to your development style?
General, I guess :)
What does your suggested rule do?
TypeScript allows me to assign a function that returns Promise to variables or parameters that are type
(...) => void
. Like:and:
(see spec 3.11.4)
I suggest a rule that disallows such assignments specifically for functions that return promises, so the caller of the given function does not unintentionally ignore the returned promise.
List several examples where your rule could be used
Given a React component that has props like:
If the database call fails this will result in an unhandled promise rejection. To be safe either
MyLists
props has to be changed, so the given function must return a promise, orsaveItem
should be changed to handle the error locally.I must admit I have no more examples right now, but for large React apps these errors can be quite hard to find and thus it might be worth a rule.
The text was updated successfully, but these errors were encountered: