typescript-eslint の の有名ルール @typescript-eslint/no-floating-promises を知る
A "floating" Promise is one that is created without any code set up to handle any errors it might throw. Floating Promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections, and more.
code:ts
const asyncTask = async () => {
if (Math.random() > 0.5) throw new Error("失敗!");
return "成功";
};
// await がない!
asyncTask();
await しなかったり、適切に catch() してなかったり、呼び出し元に return もしていないような Promise のこと This rule will report Promise-valued statements that are not treated in one of the following ways:
Calling its .then() with two arguments
Calling its .catch() with one argument
awaiting it
returning it
voiding it
voiding とは Promise の前に void を置くことで意図的に await してないってことを表明できるやつ Placing the void operator in front of a Promise can be a convenient way to explicitly mark that Promise as intentionally not awaited.