@@ -10,33 +10,34 @@ export interface Action<P> extends AnyAction {
10
10
error ?: boolean ;
11
11
meta ?: Meta ;
12
12
}
13
- export interface Success < P , S > {
13
+ export declare type RequiredKeys < T > = {
14
+ [ P in keyof T ] : T [ P ] extends undefined ? never : P ;
15
+ } [ keyof T ] ;
16
+ export declare type Optionalize < T > = Partial < T > & {
17
+ [ P in RequiredKeys < T > ] : T [ P ] ;
18
+ } ;
19
+ export declare type Success < P , S > = Optionalize < {
14
20
params : P ;
15
21
result : S ;
16
- }
17
- export interface Failure < P , E > {
22
+ } > ;
23
+ export declare type Failure < P , E > = Optionalize < {
18
24
params : P ;
19
25
error : E ;
20
- }
26
+ } > ;
21
27
export declare function isType < P > ( action : AnyAction , actionCreator : ActionCreator < P > ) : action is Action < P > ;
22
- export interface ActionCreator < P > {
28
+ export declare type ActionCreator < P > = {
23
29
type : string ;
24
30
match : ( action : AnyAction ) => action is Action < P > ;
25
- ( payload : P , meta ?: Meta ) : Action < P > ;
26
- }
27
- export interface EmptyActionCreator extends ActionCreator < undefined > {
28
- ( payload ?: undefined , meta ?: Meta ) : Action < undefined > ;
29
- }
31
+ } & ( P extends undefined ? ( payload ?: P , meta ?: Meta ) => Action < P > : ( payload : P , meta ?: Meta ) => Action < P > ) ;
30
32
export interface AsyncActionCreators < P , S , E > {
31
33
type : string ;
32
34
started : ActionCreator < P > ;
33
35
done : ActionCreator < Success < P , S > > ;
34
36
failed : ActionCreator < Failure < P , E > > ;
35
37
}
36
38
export interface ActionCreatorFactory {
37
- ( type : string , commonMeta ?: Meta , error ?: boolean ) : EmptyActionCreator ;
38
- < P > ( type : string , commonMeta ?: Meta , isError ?: boolean ) : ActionCreator < P > ;
39
- < P > ( type : string , commonMeta ?: Meta , isError ?: ( payload : P ) => boolean ) : ActionCreator < P > ;
39
+ < P = undefined > ( type : string , commonMeta ?: Meta , isError ?: boolean ) : ActionCreator < P > ;
40
+ < P = undefined > ( type : string , commonMeta ?: Meta , isError ?: ( payload : P ) => boolean ) : ActionCreator < P > ;
40
41
async < P , S > ( type : string , commonMeta ?: Meta ) : AsyncActionCreators < P , S , any > ;
41
42
async < P , S , E > ( type : string , commonMeta ?: Meta ) : AsyncActionCreators < P , S , E > ;
42
43
}
0 commit comments