@@ -4,20 +4,13 @@ import useConstant from 'use-constant'
4
4
5
5
import { RestrictArray } from './type'
6
6
7
- export type InputFactory < State , Inputs = undefined > = Inputs extends undefined
8
- ? ( state$ : Observable < State > ) => Observable < State >
9
- : ( inputs$ : Observable < RestrictArray < Inputs > > , state$ : Observable < State > ) => Observable < State >
10
-
11
- export function useObservable < State > ( inputFactory : InputFactory < State > ) : State | null
12
- export function useObservable < State > ( inputFactory : InputFactory < State > , initialState : State ) : State
13
- export function useObservable < State , Inputs > (
14
- inputFactory : InputFactory < State , Inputs > ,
15
- initialState : State ,
16
- inputs : RestrictArray < Inputs > ,
17
- ) : State
18
-
7
+ export type InputFactory < State > = ( state$ : Observable < State > ) => Observable < State > ;
8
+ export type InputFactoryWithInputs < State , Inputs > = ( inputs$ : Observable < RestrictArray < Inputs > > , state$ : Observable < State > ) => Observable < State > ;
9
+ export function useObservable < State > ( inputFactory : InputFactory < State > ) : State | null ;
10
+ export function useObservable < State > ( inputFactory : InputFactory < State > , initialState : State ) : State ;
11
+ export function useObservable < State , Inputs > ( inputFactory : InputFactoryWithInputs < State , Inputs > , initialState : State , inputs : RestrictArray < Inputs > ) : State ;
19
12
export function useObservable < State , Inputs extends ReadonlyArray < any > > (
20
- inputFactory : InputFactory < State , Inputs > ,
13
+ inputFactory : InputFactoryWithInputs < State , Inputs > ,
21
14
initialState ?: State ,
22
15
inputs ?: RestrictArray < Inputs > ,
23
16
) : State | null {
@@ -38,7 +31,7 @@ export function useObservable<State, Inputs extends ReadonlyArray<any>>(
38
31
state$ : Observable < State | undefined > ,
39
32
) => Observable < State > ) ( inputs$ , state$ ) as BehaviorSubject < State >
40
33
} else {
41
- output$ = ( inputFactory as ( state$ : Observable < State | undefined > ) => Observable < State > ) (
34
+ output$ = ( inputFactory as unknown as ( state$ : Observable < State | undefined > ) => Observable < State > ) (
42
35
state$ ,
43
36
) as BehaviorSubject < State >
44
37
}
0 commit comments