@@ -3,34 +3,34 @@ import {
3
3
ActionCreator ,
4
4
TypedAction ,
5
5
FunctionWithParametersType ,
6
- ParametersType ,
6
+ PropsReturnType ,
7
+ DisallowTypeProperty ,
7
8
} from './models' ;
8
9
9
- /**
10
- * Action creators taken from ts-action library and modified a bit to better
11
- * fit current NgRx usage. Thank you Nicholas Jamieson (@cartant).
12
- */
10
+ // Action creators taken from ts-action library and modified a bit to better
11
+ // fit current NgRx usage. Thank you Nicholas Jamieson (@cartant).
12
+
13
13
export function createAction < T extends string > (
14
14
type : T
15
15
) : ActionCreator < T , ( ) => TypedAction < T > > ;
16
16
export function createAction < T extends string , P extends object > (
17
17
type : T ,
18
18
config : { _as : 'props' ; _p : P }
19
19
) : ActionCreator < T , ( props : P ) => P & TypedAction < T > > ;
20
- export function createAction < T extends string , C extends Creator > (
20
+ export function createAction <
21
+ T extends string ,
22
+ P extends any [ ] ,
23
+ R extends object
24
+ > (
21
25
type : T ,
22
- creator : C
23
- ) : FunctionWithParametersType <
24
- ParametersType < C > ,
25
- ReturnType < C > & TypedAction < T >
26
- > &
27
- TypedAction < T > ;
28
- export function createAction < T extends string > (
26
+ creator : Creator < P , DisallowTypeProperty < R > >
27
+ ) : FunctionWithParametersType < P , R & TypedAction < T > > & TypedAction < T > ;
28
+ export function createAction < T extends string , C extends Creator > (
29
29
type : T ,
30
- config ?: { _as : 'props' } | Creator
30
+ config ?: { _as : 'props' } | C
31
31
) : Creator {
32
32
if ( typeof config === 'function' ) {
33
- return defineType ( type , ( ...args : unknown [ ] ) => ( {
33
+ return defineType ( type , ( ...args : any [ ] ) => ( {
34
34
...config ( ...args ) ,
35
35
type,
36
36
} ) ) ;
@@ -40,17 +40,19 @@ export function createAction<T extends string>(
40
40
case 'empty' :
41
41
return defineType ( type , ( ) => ( { type } ) ) ;
42
42
case 'props' :
43
- return defineType ( type , ( props : unknown ) => ( {
44
- ...( props as object ) ,
43
+ return defineType ( type , ( props : object ) => ( {
44
+ ...props ,
45
45
type,
46
46
} ) ) ;
47
47
default :
48
48
throw new Error ( 'Unexpected config.' ) ;
49
49
}
50
50
}
51
51
52
- export function props < P > ( ) : { _as : 'props' ; _p : P } {
53
- return { _as : 'props' , _p : undefined ! } ;
52
+ export function props < P extends object > ( ) : PropsReturnType < P > {
53
+ // the return type does not match TypePropertyIsNotAllowed, so double casting
54
+ // is used.
55
+ return ( { _as : 'props' , _p : undefined ! } as unknown ) as PropsReturnType < P > ;
54
56
}
55
57
56
58
export function union <
0 commit comments