File tree 2 files changed +12
-10
lines changed
2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 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 */
4
1
import { Act } from '../types/react'
5
2
6
3
import { suppressErrorOutput } from './console'
7
4
5
+ import { isPromise } from './promises'
6
+
8
7
function createActWrapper ( baseAct : Act ) {
9
- const act : Act = async ( callback : ( ) => any ) => {
8
+ const act : Act = async ( callback : ( ) => unknown ) => {
10
9
const restoreOutput = suppressErrorOutput ( )
11
10
try {
12
11
let awaitRequired = false
13
- const actResult = ( baseAct ( ( ) => {
12
+ const actResult = baseAct ( ( ) => {
14
13
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
+ } )
19
17
return awaitRequired ? await actResult : undefined
20
18
} finally {
21
19
restoreOutput ( )
Original file line number Diff line number Diff line change @@ -7,4 +7,8 @@ async function callAfter(callback: () => void, ms: number) {
7
7
callback ( )
8
8
}
9
9
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 }
You can’t perform that action at this time.
0 commit comments