diff --git a/src/helpers/act.ts b/src/helpers/act.ts index 0f8acea4..895560d9 100644 --- a/src/helpers/act.ts +++ b/src/helpers/act.ts @@ -1,21 +1,19 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { Act } from '../types/react' import { suppressErrorOutput } from './console' +import { isPromise } from './promises' + function createActWrapper(baseAct: Act) { - const act: Act = async (callback: () => any) => { + const act: Act = async (callback: () => unknown) => { const restoreOutput = suppressErrorOutput() try { let awaitRequired = false - const actResult = (baseAct(() => { + const actResult = baseAct(() => { const callbackResult = callback() - awaitRequired = callbackResult !== undefined && !!callbackResult.then - return callbackResult - }) as any) as PromiseLike - + awaitRequired = isPromise(callbackResult) + return callbackResult as Promise + }) return awaitRequired ? await actResult : undefined } finally { restoreOutput() diff --git a/src/helpers/promises.ts b/src/helpers/promises.ts index 2fa89e5f..a3a59e76 100644 --- a/src/helpers/promises.ts +++ b/src/helpers/promises.ts @@ -7,4 +7,8 @@ async function callAfter(callback: () => void, ms: number) { callback() } -export { resolveAfter, callAfter } +function isPromise(value: unknown): boolean { + return value !== undefined && typeof (value as PromiseLike).then === 'function' +} + +export { resolveAfter, callAfter, isPromise }