File tree 1 file changed +5
-3
lines changed
packages/shared/createEventHook
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,14 @@ type Callback<T> = IsAny<T> extends true
12
12
: (
13
13
[ T ] extends [ void ]
14
14
? ( ...param : unknown [ ] ) => void
15
- : ( ...param : [ T , ...unknown [ ] ] ) => void
15
+ : [ T ] extends [ any [ ] ]
16
+ ? ( ...param : T ) => void
17
+ : ( ...param : [ T , ...unknown [ ] ] ) => void
16
18
)
17
19
18
20
export type EventHookOn < T = any > = ( fn : Callback < T > ) => { off : ( ) => void }
19
21
export type EventHookOff < T = any > = ( fn : Callback < T > ) => void
20
- export type EventHookTrigger < T = any > = ( ...param : IsAny < T > extends true ? unknown [ ] : [ T , ... unknown [ ] ] ) => Promise < unknown [ ] >
22
+ export type EventHookTrigger < T = any > = ( ...param : Parameters < Callback < T > > ) => Promise < unknown [ ] >
21
23
22
24
export interface EventHook < T = any > {
23
25
on : EventHookOn < T >
@@ -54,7 +56,7 @@ export function createEventHook<T = any>(): EventHook<T> {
54
56
}
55
57
56
58
const trigger : EventHookTrigger < T > = ( ...args ) => {
57
- return Promise . all ( Array . from ( fns ) . map ( fn => fn ( ...( args as [ T , ... unknown [ ] ] ) ) ) )
59
+ return Promise . all ( Array . from ( fns ) . map ( fn => fn ( ...args ) ) )
58
60
}
59
61
60
62
return {
You can’t perform that action at this time.
0 commit comments