From 2d5b410712961a56031dd9b8531f5349ca32c781 Mon Sep 17 00:00:00 2001 From: hieu-w Date: Mon, 20 Jan 2025 14:21:06 +0700 Subject: [PATCH] Fix torus-cli build --- src/some.ts | 82 ++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/src/some.ts b/src/some.ts index 60ee0b1..7ca0b8b 100644 --- a/src/some.ts +++ b/src/some.ts @@ -46,7 +46,8 @@ export const Some = (promises: Promise[], predicate: (resultArr: K[], { let predicateError: Error | string; promises.forEach((x, index) => { - x.then((resp: K) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + x.then((resp: K): any => { resultArr[index] = resp; return undefined; }) @@ -56,47 +57,50 @@ export const Some = (promises: Promise[], predicate: (resultArr: K[], { // eslint-disable-next-line promise/no-return-in-finally .finally(() => { if (sharedState.resolved) return; - return predicate(resultArr.slice(0), sharedState) - .then((data) => { - sharedState.resolved = true; - resolve(data); - return undefined; - }) - .catch((error) => { - // log only the last predicate error - predicateError = error; - }) - .finally(() => { - finishedCount += 1; - if (finishedCount === promises.length) { - const errors = Object.values( - resultArr.reduce((acc: Record, z) => { - if (z) { - const { id, error } = z as { id?: string; error?: { data?: string } }; - if (error?.data?.length > 0) { - if (error.data.startsWith("Error occurred while verifying params")) acc[id] = capitalizeFirstLetter(error.data); - else acc[id] = error.data; + return ( + predicate(resultArr.slice(0), sharedState) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .then((data): any => { + sharedState.resolved = true; + resolve(data); + return undefined; + }) + .catch((error) => { + // log only the last predicate error + predicateError = error; + }) + .finally(() => { + finishedCount += 1; + if (finishedCount === promises.length) { + const errors = Object.values( + resultArr.reduce((acc: Record, z) => { + if (z) { + const { id, error } = z as { id?: string; error?: { data?: string } }; + if (error?.data?.length > 0) { + if (error.data.startsWith("Error occurred while verifying params")) acc[id] = capitalizeFirstLetter(error.data); + else acc[id] = error.data; + } } - } - return acc; - }, {}) - ); - - if (errors.length > 0) { - // Format-able errors - const msg = errors.length > 1 ? `\n${errors.map((it) => `• ${it}`).join("\n")}` : errors[0]; - reject(new Error(msg)); - } else { - reject( - new SomeError({ - errors: errorArr, - responses: resultArr, - predicate: (predicateError as Error)?.message || (predicateError as string), - }) + return acc; + }, {}) ); + + if (errors.length > 0) { + // Format-able errors + const msg = errors.length > 1 ? `\n${errors.map((it) => `• ${it}`).join("\n")}` : errors[0]; + reject(new Error(msg)); + } else { + reject( + new SomeError({ + errors: errorArr, + responses: resultArr, + predicate: (predicateError as Error)?.message || (predicateError as string), + }) + ); + } } - } - }); + }) + ); }); }); });