Skip to content

Commit b8b9c8b

Browse files
committed
refactor: reduce eslint-warnings & type changes
1 parent cdc351a commit b8b9c8b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/helpers/act.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
3-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
41
import { Act } from '../types/react'
52

63
import { suppressErrorOutput } from './console'
74

5+
import { isPromise } from './promises'
6+
87
function createActWrapper(baseAct: Act) {
9-
const act: Act = async (callback: () => any) => {
8+
const act: Act = async (callback: () => unknown) => {
109
const restoreOutput = suppressErrorOutput()
1110
try {
1211
let awaitRequired = false
13-
const actResult = (baseAct(() => {
12+
const actResult = baseAct(() => {
1413
const callbackResult = callback()
15-
awaitRequired = callbackResult !== undefined && !!callbackResult.then
16-
return callbackResult
17-
}) as any) as PromiseLike<undefined>
18-
14+
awaitRequired = isPromise(callbackResult)
15+
return callbackResult as Promise<void>
16+
})
1917
return awaitRequired ? await actResult : undefined
2018
} finally {
2119
restoreOutput()

src/helpers/promises.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ async function callAfter(callback: () => void, ms: number) {
77
callback()
88
}
99

10-
export { resolveAfter, callAfter }
10+
function isPromise<T>(value: unknown): boolean {
11+
return value !== undefined && typeof (value as PromiseLike<T>).then === 'function'
12+
}
13+
14+
export { resolveAfter, callAfter, isPromise }

0 commit comments

Comments
 (0)