Permalink
Browse files

feat(typings): Adds type definitions for ActionsObservable.from/of

  • Loading branch information...
jayphelps committed Nov 17, 2016
1 parent fd393a1 commit 0cba5578056f9def9eed06139e8222c663b79a9c
Showing with 26 additions and 5 deletions.
  1. +20 −1 index.d.ts
  2. +6 −4 test/typings.ts
@@ -1,8 +1,27 @@
import { Middleware, MiddlewareAPI } from 'redux';
import { Observable } from 'rxjs/Observable';
import { Observable, ObservableInput } from 'rxjs/Observable';
import { Scheduler } from 'rxjs/Scheduler';
import { Operator } from 'rxjs/Operator';

export declare class ActionsObservable<T> extends Observable<T> {
/**
* Just like RxJS itself, we can't actually make this method always type-safe
* because we would need non-final position spread params e.g.
* `static of<T>(...items: T, scheduler?: Scheduler): ActionsObservable<T>`
* which isn't possible in either JavaScript or TypeScript. So instead, we
* provide safe typing for up to 6 items, following by a scheduler.
*/
static of<T>(item1: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(item1: T, item2: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(item1: T, item2: T, item3: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: Scheduler): ActionsObservable<T>;
static of<T>(...array: Array<T | Scheduler>): ActionsObservable<T>;

static from<T>(ish: ObservableInput<T>, scheduler?: Scheduler): ActionsObservable<T>;
static from<T, R>(ish: ArrayLike<T>, scheduler?: Scheduler): ActionsObservable<R>;

constructor(input$: Observable<T>);
lift(operator: Operator<any, T>) : ActionsObservable<T>;
ofType(...key: any[]) : ActionsObservable<T>;
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { createStore, applyMiddleware } from 'redux';
import { Observable } from 'rxjs/Observable';
import { asap } from 'rxjs/scheduler/asap';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/mapTo';
import 'rxjs/add/operator/map';
@@ -59,10 +60,6 @@ const rootEpic2 = combineEpics(epic1, epic2, epic3, epic4, epic5, epic6);
const epicMiddleware1: EpicMiddleware<FluxStandardAction> = createEpicMiddleware<FluxStandardAction>(rootEpic1);
const epicMiddleware2 = createEpicMiddleware(rootEpic2);

// should be a constructor that returns an observable
const input$ = Observable.create(() => {});
const action$: ActionsObservable<FluxStandardAction> = new ActionsObservable<FluxStandardAction>(input$);

const reducer = (state = [], action) => state.concat(action);
const store = createStore(
reducer,
@@ -115,4 +112,9 @@ expect(store.getState()).to.deep.equal([
{ "type": "sixth", "payload": "sixth-payload" }
]);

const input$ = Observable.create(() => {});
const action$1: ActionsObservable<FluxStandardAction> = new ActionsObservable<FluxStandardAction>(input$);
const action$2: ActionsObservable<FluxStandardAction> = ActionsObservable.of<FluxStandardAction>({ type: 'SECOND' }, { type: 'FIRST' }, asap);
const action$3: ActionsObservable<FluxStandardAction> = ActionsObservable.from<FluxStandardAction>([{ type: 'SECOND' }, { type: 'FIRST' }], asap);

console.log('typings.ts: OK');

0 comments on commit 0cba557

Please sign in to comment.