@@ -3,34 +3,34 @@ import {
33 ActionCreator ,
44 TypedAction ,
55 FunctionWithParametersType ,
6- ParametersType ,
6+ PropsReturnType ,
7+ DisallowTypeProperty ,
78} from './models' ;
89
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+
1313export function createAction < T extends string > (
1414 type : T
1515) : ActionCreator < T , ( ) => TypedAction < T > > ;
1616export function createAction < T extends string , P extends object > (
1717 type : T ,
1818 config : { _as : 'props' ; _p : P }
1919) : 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+ > (
2125 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 > (
2929 type : T ,
30- config ?: { _as : 'props' } | Creator
30+ config ?: { _as : 'props' } | C
3131) : Creator {
3232 if ( typeof config === 'function' ) {
33- return defineType ( type , ( ...args : unknown [ ] ) => ( {
33+ return defineType ( type , ( ...args : any [ ] ) => ( {
3434 ...config ( ...args ) ,
3535 type,
3636 } ) ) ;
@@ -40,17 +40,19 @@ export function createAction<T extends string>(
4040 case 'empty' :
4141 return defineType ( type , ( ) => ( { type } ) ) ;
4242 case 'props' :
43- return defineType ( type , ( props : unknown ) => ( {
44- ...( props as object ) ,
43+ return defineType ( type , ( props : object ) => ( {
44+ ...props ,
4545 type,
4646 } ) ) ;
4747 default :
4848 throw new Error ( 'Unexpected config.' ) ;
4949 }
5050}
5151
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 > ;
5456}
5557
5658export function union <
0 commit comments