@@ -3,8 +3,10 @@ import { Observable, BehaviorSubject, Subject, noop } from 'rxjs'
33
44import { RestrictArray , VoidAsNull , Not } from './type'
55
6+ type VoidableCallback < EventValue > = EventValue extends void ? ( ) => void : ( val : EventValue ) => void
7+
68export type EventCallbackState < EventValue , State , Inputs = void > = [
7- ( val : EventValue ) => void ,
9+ VoidableCallback < EventValue > ,
810 [ State extends void ? null : State , BehaviorSubject < State | null > , BehaviorSubject < RestrictArray < Inputs > | null > ]
911]
1012export type ReturnedState < EventValue , State , Inputs > = [
@@ -44,7 +46,9 @@ export function useEventCallback<EventValue, State = void, Inputs = void>(
4446 const inputSubject$ = new BehaviorSubject < RestrictArray < Inputs > | null > ( typeof inputs === 'undefined' ? null : inputs )
4547 const stateSubject$ = new BehaviorSubject < State | null > ( initialValue )
4648 const [ state , setState ] = useState ( initialValue )
47- const [ returnedCallback , setEventCallback ] = useState < ( val : EventValue ) => void > ( ( ) => noop )
49+ const [ returnedCallback , setEventCallback ] = useState < VoidableCallback < EventValue > > (
50+ ( ) => noop as VoidableCallback < EventValue > ,
51+ )
4852 const [ state$ ] = useState ( stateSubject$ )
4953 const [ inputs$ ] = useState ( inputSubject$ )
5054
@@ -58,7 +62,7 @@ export function useEventCallback<EventValue, State = void, Inputs = void>(
5862 return event$ . next ( e )
5963 }
6064 setState ( initialValue )
61- setEventCallback ( ( ) => eventCallback )
65+ setEventCallback ( ( ) => eventCallback as VoidableCallback < EventValue > )
6266 let value$ : Observable < State >
6367
6468 if ( ! inputs ) {
0 commit comments