Closed as not planned
Closed as not planned
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
The no-misused-promises
documentation does not explain the motivation for the rule, so I'm left to infer that it is because promise rejections are not handled properly. There are a couple references to no-floating-promises
in the docs, which support this view. However, if a function is wrapped entirely in a try
/catch
then we know it can never error and so any triggering of this rule would be a false positive
Fail
/** @type {NodeJS.Timeout} */
let timeout;
/** @type {() => Promise<boolean>} */
async function check() {
clearTimeout(timeout);
// this line would fail because check is async and setTimeout expects a synchronous function
if (interval) timeout = setTimeout(check, interval);
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
headers: {
pragma: 'no-cache',
'cache-control': 'no-cache'
}
});
if (!res.ok) {
return false;
}
const data = await res.json();
const updated = data.version !== version;
if (updated) {
set(true);
clearTimeout(timeout);
}
return updated;
}
// this line would fail because check is async and setTimeout expects a synchronous function
if (interval) timeout = setTimeout(check, interval);
Pass
/** @type {NodeJS.Timeout} */
let timeout;
/** @type {() => Promise<boolean>} */
async function check() {
try {
clearTimeout(timeout);
// this can't fail since the contents of check is wrapped in a try/catch
if (interval) timeout = setTimeout(check, interval);
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
headers: {
pragma: 'no-cache',
'cache-control': 'no-cache'
}
});
if (!res.ok) {
return false;
}
const data = await res.json();
const updated = data.version !== version;
if (updated) {
set(true);
clearTimeout(timeout);
}
return updated;
} catch {
return false;
}
}
// this can't fail since the contents of check is wrapped in a try/catch
if (interval) timeout = setTimeout(check, interval);
Additional Info
No response