Permalink
Browse files

fix(TypeScript type definition): Add combineEpics(), provide more acc…

…urate type info for others (#70)

fixes #69
  • Loading branch information...
jayphelps committed Jul 14, 2016
1 parent 7ea9b6f commit 20da88c76690cd362039e51c34411b2090a583da
Showing with 31 additions and 23 deletions.
  1. +11 −19 index.d.ts
  2. +20 −4 test/typings.ts
@@ -1,25 +1,17 @@
import { Middleware } from 'redux';
import { Middleware, MiddlewareAPI, Action } from 'redux';
import { Observable } from 'rxjs/Observable';
import { Operator } from 'rxjs/Operator';

export declare function createEpicMiddleware(): Middleware;

// ./node_modules/rxjs/Observable.d.ts
export declare class ActionsObservable<T> extends Observable<T> {
export declare class ActionsObservable extends Observable<Action> {
constructor(actionsSubject: Observable<Action>);
lift(operator: Operator<any, Action>);
ofType(...key: any[]);
}

// ./node_modules/rxjs/Observable.d.ts specifies an `Observable`'s `source`
// property like so: `protected source: Observable<any>;`
// since `actionsSubject` is being assigned to an `Observable`'s `source`
// property it is being given the type: `Observable<any>`
constructor(actionsSubject: Observable<any>);
export declare interface Epic {
(action$: ActionsObservable, store: MiddlewareAPI<any>): Observable<Action>;
}

// ./node_modules/rxjs/Observable.d.ts specifies operators as generics like so
// `protected operator: Operator<any, T>;`
lift(operator: Operator<any, T>);
export declare function createEpicMiddleware(...epics: Epic[]): Middleware;

// ./node_modules/redux/index.d.ts specifies `Action` as having a `type`
// property with a type signature of `any`
// since `key` is being compared with an `Action`'s `type`, `key` has a type
// signature of `any`
ofType(...key: any[]);
}
export declare function combineEpics(...epics: Epic[]): Epic;
@@ -1,9 +1,25 @@
import { createEpicMiddleware, ActionsObservable } from '../index';
import { createEpicMiddleware, combineEpics, ActionsObservable } from '../index';
import { Action } from 'redux';
import { Observable } from 'rxjs/Observable';

// should be a function
createEpicMiddleware();
const epic1 = (action$, store) =>
action$.ofType('FIRST')
.mapTo({
type: 'first',
payload: store.getState()
});

const epic2 = (action$, store) =>
action$.ofType('SECOND')
.mapTo({
type: 'second',
payload: store.getState()
});

const rootEpic = combineEpics(epic1, epic2);

createEpicMiddleware(rootEpic);

// should be a constructor that returns an observable
const actionsSubject = Observable.create(() => {});
const aoTest: Observable<string> = new ActionsObservable(actionsSubject);
const aoTest: Observable<Action> = new ActionsObservable(actionsSubject);

0 comments on commit 20da88c

Please sign in to comment.