1
1
import { compose } from '@ngrx/store' ;
2
- import { EffectMetadata , EffectConfig } from './models' ;
2
+
3
+ import { EffectConfig , EffectMetadata , EffectPropertyKey } from './models' ;
3
4
import { getSourceForInstance } from './utils' ;
4
5
5
6
const METADATA_KEY = '__@ngrx/effects__' ;
6
7
7
- export function Effect < T > ( {
8
+ export function Effect ( {
8
9
dispatch = true ,
9
10
resubscribeOnError = true ,
10
- } : EffectConfig = { } ) : PropertyDecorator {
11
- return function < K extends Extract < keyof T , string > > (
11
+ } : EffectConfig = { } ) {
12
+ return function < T extends Object , K extends EffectPropertyKey < T > > (
12
13
target : T ,
13
14
propertyName : K
14
15
) {
@@ -21,7 +22,7 @@ export function Effect<T>({
21
22
resubscribeOnError,
22
23
} ;
23
24
setEffectMetadataEntries < T > ( target , [ metadata ] ) ;
24
- } as ( target : { } , propertyName : string | symbol ) => void ;
25
+ } ;
25
26
}
26
27
27
28
export function getEffectDecoratorMetadata < T > (
@@ -35,7 +36,7 @@ export function getEffectDecoratorMetadata<T>(
35
36
return effectsDecorators ;
36
37
}
37
38
38
- function setEffectMetadataEntries < T > (
39
+ function setEffectMetadataEntries < T extends object > (
39
40
sourceProto : T ,
40
41
entries : EffectMetadata < T > [ ]
41
42
) {
@@ -50,8 +51,12 @@ function setEffectMetadataEntries<T>(
50
51
Array . prototype . push . apply ( meta , entries ) ;
51
52
}
52
53
53
- function getEffectMetadataEntries < T > ( sourceProto : T ) : EffectMetadata < T > [ ] {
54
+ function getEffectMetadataEntries < T extends object > (
55
+ sourceProto : T
56
+ ) : EffectMetadata < T > [ ] {
54
57
return sourceProto . constructor . hasOwnProperty ( METADATA_KEY )
55
- ? ( sourceProto . constructor as any ) [ METADATA_KEY ]
58
+ ? ( sourceProto . constructor as typeof sourceProto . constructor & {
59
+ [ METADATA_KEY ] : EffectMetadata < T > [ ] ;
60
+ } ) [ METADATA_KEY ]
56
61
: [ ] ;
57
62
}
0 commit comments