Skip to content

Commit 636b866

Browse files
isimehmetiilyaliaoautofix-ci[bot]
authored
fix(createEventHook): type check for multiple arguments (#4555)
Co-authored-by: IlyaL <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 93591c4 commit 636b866

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: packages/shared/createEventHook/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ type Callback<T> = IsAny<T> extends true
1212
: (
1313
[T] extends [void]
1414
? (...param: unknown[]) => void
15-
: (...param: [T, ...unknown[]]) => void
15+
: [T] extends [any[]]
16+
? (...param: T) => void
17+
: (...param: [T, ...unknown[]]) => void
1618
)
1719

1820
export type EventHookOn<T = any> = (fn: Callback<T>) => { off: () => void }
1921
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[]>
2123

2224
export interface EventHook<T = any> {
2325
on: EventHookOn<T>
@@ -54,7 +56,7 @@ export function createEventHook<T = any>(): EventHook<T> {
5456
}
5557

5658
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)))
5860
}
5961

6062
return {

0 commit comments

Comments
 (0)