Skip to content

Commit 6b98f77

Browse files
committed
feat(use-event-callback): smarter useEventCallback type
1 parent 5d0e490 commit 6b98f77

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/use-event-callback.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { Observable, BehaviorSubject, Subject } from 'rxjs'
33

44
import { RestrictArray, VoidAsNull, Not } from './type'
55

6+
export type VoidableEventCallback<EventValue> = EventValue extends void ? () => void : (e: EventValue) => void
7+
68
export type EventCallbackState<EventValue, State, Inputs = void> = [
7-
(e: EventValue) => void,
9+
VoidableEventCallback<EventValue>,
810
[State extends void ? null : State, BehaviorSubject<State | null>, BehaviorSubject<RestrictArray<Inputs> | null>]
911
]
1012
export type ReturnedState<EventValue, State, Inputs> = [
@@ -77,5 +79,5 @@ export function useEventCallback<EventValue, State = void, Inputs = void>(
7779
}
7880
}, []) // immutable forever
7981

80-
return [returnedCallback, state]
82+
return [returnedCallback as VoidableEventCallback<EventValue>, state]
8183
}

0 commit comments

Comments
 (0)