diff --git a/modules/store/spec/edge.spec.ts b/modules/store/spec/edge.spec.ts index 43079ef112..0cced79ec0 100644 --- a/modules/store/spec/edge.spec.ts +++ b/modules/store/spec/edge.spec.ts @@ -38,7 +38,7 @@ describe('ngRx Store', () => { let todosNextCount = 0; let todosCountNextCount = 0; - store.pipe(select('todos')).subscribe(todos => { + store.pipe(select('todos')).subscribe(todos => { todosNextCount++; store.dispatch({ type: 'SET_COUNT', payload: todos.length }); }); diff --git a/modules/store/src/store.ts b/modules/store/src/store.ts index b9d5d92771..e689d1628a 100644 --- a/modules/store/src/store.ts +++ b/modules/store/src/store.ts @@ -29,7 +29,7 @@ export class Store extends Observable implements Observer { key1: a, key2: b, key3: c - ): Store; + ): Observable; select< a extends keyof T, b extends keyof T[a], @@ -62,15 +62,12 @@ export class Store extends Observable implements Observer { * This overload is used to support spread operator with * fixed length tuples type in typescript 2.7 */ - select( - pathOrMapFn: ((state: T) => any) | string, - ...paths: string[] - ): Observable; + select(...paths: string[]): Observable; select( pathOrMapFn: ((state: T) => any) | string, ...paths: string[] ): Observable { - return select(pathOrMapFn, ...paths)(this); + return select.call(null, pathOrMapFn, ...paths)(this); } lift(operator: Operator): Store { @@ -111,21 +108,25 @@ export class Store extends Observable implements Observer { export const STORE_PROVIDERS: Provider[] = [Store]; export function select( - mapFn: ((state: T) => K) | string + mapFn: (state: T) => K ): (source$: Observable) => Observable; export function select( key: a -): (source$: Store) => Observable; +): (source$: Observable) => Observable; export function select( key1: a, key2: b -): (source$: Store) => Observable; +): (source$: Observable) => Observable; export function select< T, a extends keyof T, b extends keyof T[a], c extends keyof T[a][b] ->(key1: a, key2: b, key3: c): (source$: Store) => Observable; +>( + key1: a, + key2: b, + key3: c +): (source$: Observable) => Observable; export function select< T, a extends keyof T, @@ -137,7 +138,7 @@ export function select< key2: b, key3: c, key4: d -): (source$: Store) => Observable; +): (source$: Observable) => Observable; export function select< T, a extends keyof T, @@ -151,7 +152,7 @@ export function select< key3: c, key4: d, key5: e -): (source$: Store) => Observable; +): (source$: Observable) => Observable; export function select< T, a extends keyof T, @@ -167,20 +168,19 @@ export function select< key4: d, key5: e, key6: f -): (source$: Store) => Observable; +): (source$: Observable) => Observable; /** * This overload is used to support spread operator with * fixed length tuples type in typescript 2.7 */ -export function select( - pathOrMapFn: ((state: T) => any) | string, +export function select( ...paths: string[] -): (source$: Store) => Observable; +): (source$: Observable) => Observable; export function select( pathOrMapFn: ((state: T) => any) | string, ...paths: string[] ) { - return function selectOperator(source$: Store): Observable { + return function selectOperator(source$: Observable): Observable { let mapped$: Observable; if (typeof pathOrMapFn === 'string') {