Skip to content

Commit

Permalink
refactor(store): adjust types to be compatible with TypeScript 2.7 an…
Browse files Browse the repository at this point in the history
…d 2.9 (#1193)
  • Loading branch information
alex-okrushko authored and brandonroberts committed Jul 25, 2018
1 parent 97269c0 commit 22284ab
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/effects/src/effects_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { compose } from '@ngrx/store';
const METADATA_KEY = '__@ngrx/effects__';

export interface EffectMetadata<T> {
propertyName: keyof T;
// Once TS is >= 2.8 replace with <Key extends Extract<keyof T, string>>
propertyName: string;
dispatch: boolean;
}

Expand All @@ -29,7 +30,9 @@ function setEffectMetadataEntries<T>(
}

export function Effect<T>({ dispatch = true } = {}): PropertyDecorator {
return function(target: T, propertyName: keyof T) {
// Once TS is >= 2.8 replace with <Key extends Extract<keyof T, string>>
// for propertyName.
return function(target: T, propertyName: string) {
const metadata: EffectMetadata<T> = { propertyName, dispatch };
setEffectMetadataEntries<T>(target, [metadata]);
} as (target: {}, propertyName: string | symbol) => void;
Expand All @@ -46,7 +49,9 @@ export function getSourceMetadata<T>(instance: T): Array<EffectMetadata<T>> {
)(instance);
}

export type EffectsMetadata<T> = { [key in keyof T]?: { dispatch: boolean } };
// Once TS is >= 2.8 replace with
// {[key in <Key extends Extract<keyof T, string>>]?: { dispatch: boolean } };
export type EffectsMetadata<T> = { [key: string]: { dispatch: boolean } };

export function getEffectsMetadata<T>(instance: T): EffectsMetadata<T> {
const metadata: EffectsMetadata<T> = {};
Expand Down

0 comments on commit 22284ab

Please sign in to comment.