@@ -77,13 +77,18 @@ function App() {
77
77
### ` useObservable `
78
78
79
79
``` tsx
80
- declare type InputFactory <T , U = undefined > = U extends undefined
81
- ? (state$ : Observable <T >) => Observable <T >
82
- : (inputs$ : Observable <U >, state$ : Observable <T >) => Observable <T >
83
-
84
- declare function useObservable<T >(inputFactory : InputFactory <T >): T | null
85
- declare function useObservable<T >(inputFactory : InputFactory <T >, initialState : T ): T
86
- declare function useObservable<T , U >(inputFactory : InputFactory <T , U >, initialState : T , inputs : U ): T
80
+ type RestrictArray <T > = T extends any [] ? T : []
81
+ type InputFactory <State , Inputs = undefined > = Inputs extends undefined
82
+ ? (state$ : Observable <State >) => Observable <State >
83
+ : (inputs$ : Observable <RestrictArray <Inputs >>, state$ : Observable <State >) => Observable <State >
84
+
85
+ declare function useObservable<State >(inputFactory : InputFactory <State >): State | null
86
+ declare function useObservable<State >(inputFactory : InputFactory <State >, initialState : State ): State
87
+ declare function useObservable<State , Inputs >(
88
+ inputFactory : InputFactory <State , Inputs >,
89
+ initialState : State ,
90
+ inputs : RestrictArray <Inputs >,
91
+ ): State
87
92
```
88
93
89
94
#### Examples :
@@ -181,30 +186,38 @@ ReactDOM.render(<App />, document.querySelector('#root'))
181
186
### ` useEventCallback `
182
187
183
188
` ` ` tsx
184
- declare type VoidAsNull<T> = T extends void ? null : T
189
+ type RestrictArray<T> = T extends any[] ? T : []
190
+ type VoidAsNull<T> = T extends void ? null : T
185
191
186
- declare type EventCallbackState<_T, E, U, I = void> = [
187
- (e: E) => void,
188
- [U extends void ? null : U, BehaviorSubject<U | null>, BehaviorSubject<I | null>]
192
+ type EventCallbackState<EventValue, State, Inputs = void> = [
193
+ (val: EventValue) => void,
194
+ [State extends void ? null : State, BehaviorSubject<State | null>, BehaviorSubject<RestrictArray<Inputs> | null>]
195
+ ]
196
+ type ReturnedState<EventValue, State, Inputs> = [
197
+ EventCallbackState<EventValue, State, Inputs>[0],
198
+ EventCallbackState<EventValue, State, Inputs>[1][0]
189
199
]
190
- declare type ReturnedState<T, E, U, I> = [EventCallbackState<T, E, U, I>[0], EventCallbackState<T, E, U, I>[1][0]]
191
-
192
- declare type EventCallback<_T, E, U, I> = I extends void
193
- ? (eventSource$: Observable<E>, state$: Observable<U>) => Observable<U>
194
- : (eventSource$: Observable<E>, inputs$: Observable<I>, state$: Observable<U>) => Observable<U>
195
-
196
- declare function useEventCallback<T, E extends SyntheticEvent<T>, U = void>(
197
- callback: EventCallback<T, E, U, void>,
198
- ): ReturnedState<T, E, U | null, void>
199
- declare function useEventCallback<T, E extends SyntheticEvent<T>, U = void>(
200
- callback: EventCallback<T, E, U, void>,
201
- initialState: U,
202
- ): ReturnedState<T, E, U, void>
203
- declare function useEventCallback<T, E extends SyntheticEvent<T>, U = void, I = void>(
204
- callback: EventCallback<T, E, U, I>,
205
- initialState: U,
206
- inputs: I,
207
- ): ReturnedState<T, E, U, I>
200
+
201
+ type EventCallback<EventValue, State, Inputs> = Inputs extends void
202
+ ? (eventSource$: Observable<EventValue>, state$: Observable<State>) => Observable<State>
203
+ : (
204
+ eventSource$: Observable<EventValue>,
205
+ inputs$: Observable<RestrictArray<Inputs>>,
206
+ state$: Observable<State>,
207
+ ) => Observable<State>
208
+
209
+ declare function useEventCallback<EventValue, State = void>(
210
+ callback: EventCallback<EventValue, State, void>,
211
+ ): ReturnedState<EventValue, State | null, void>
212
+ declare function useEventCallback<EventValue, State = void>(
213
+ callback: EventCallback<EventValue, State, void>,
214
+ initialState: State,
215
+ ): ReturnedState<EventValue, State, void>
216
+ declare function useEventCallback<EventValue, State = void, Inputs = void>(
217
+ callback: EventCallback<EventValue, State, Inputs>,
218
+ initialState: State,
219
+ inputs: RestrictArray<Inputs>,
220
+ ): ReturnedState<EventValue, State, Inputs>
208
221
` ` `
209
222
210
223
#### Examples :
0 commit comments