Skip to content

Commit 0cba557

Browse files
committed
feat(typings): Adds type definitions for ActionsObservable.from/of
1 parent fd393a1 commit 0cba557

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

index.d.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import { Middleware, MiddlewareAPI } from 'redux';
2-
import { Observable } from 'rxjs/Observable';
2+
import { Observable, ObservableInput } from 'rxjs/Observable';
3+
import { Scheduler } from 'rxjs/Scheduler';
34
import { Operator } from 'rxjs/Operator';
45

56
export declare class ActionsObservable<T> extends Observable<T> {
7+
/**
8+
* Just like RxJS itself, we can't actually make this method always type-safe
9+
* because we would need non-final position spread params e.g.
10+
* `static of<T>(...items: T, scheduler?: Scheduler): ActionsObservable<T>`
11+
* which isn't possible in either JavaScript or TypeScript. So instead, we
12+
* provide safe typing for up to 6 items, following by a scheduler.
13+
*/
14+
static of<T>(item1: T, scheduler?: Scheduler): ActionsObservable<T>;
15+
static of<T>(item1: T, item2: T, scheduler?: Scheduler): ActionsObservable<T>;
16+
static of<T>(item1: T, item2: T, item3: T, scheduler?: Scheduler): ActionsObservable<T>;
17+
static of<T>(item1: T, item2: T, item3: T, item4: T, scheduler?: Scheduler): ActionsObservable<T>;
18+
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: Scheduler): ActionsObservable<T>;
19+
static of<T>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: Scheduler): ActionsObservable<T>;
20+
static of<T>(...array: Array<T | Scheduler>): ActionsObservable<T>;
21+
22+
static from<T>(ish: ObservableInput<T>, scheduler?: Scheduler): ActionsObservable<T>;
23+
static from<T, R>(ish: ArrayLike<T>, scheduler?: Scheduler): ActionsObservable<R>;
24+
625
constructor(input$: Observable<T>);
726
lift(operator: Operator<any, T>) : ActionsObservable<T>;
827
ofType(...key: any[]) : ActionsObservable<T>;

test/typings.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22
import { createStore, applyMiddleware } from 'redux';
33
import { Observable } from 'rxjs/Observable';
4+
import { asap } from 'rxjs/scheduler/asap';
45
import 'rxjs/add/observable/of';
56
import 'rxjs/add/operator/mapTo';
67
import 'rxjs/add/operator/map';
@@ -59,10 +60,6 @@ const rootEpic2 = combineEpics(epic1, epic2, epic3, epic4, epic5, epic6);
5960
const epicMiddleware1: EpicMiddleware<FluxStandardAction> = createEpicMiddleware<FluxStandardAction>(rootEpic1);
6061
const epicMiddleware2 = createEpicMiddleware(rootEpic2);
6162

62-
// should be a constructor that returns an observable
63-
const input$ = Observable.create(() => {});
64-
const action$: ActionsObservable<FluxStandardAction> = new ActionsObservable<FluxStandardAction>(input$);
65-
6663
const reducer = (state = [], action) => state.concat(action);
6764
const store = createStore(
6865
reducer,
@@ -115,4 +112,9 @@ expect(store.getState()).to.deep.equal([
115112
{ "type": "sixth", "payload": "sixth-payload" }
116113
]);
117114

115+
const input$ = Observable.create(() => {});
116+
const action$1: ActionsObservable<FluxStandardAction> = new ActionsObservable<FluxStandardAction>(input$);
117+
const action$2: ActionsObservable<FluxStandardAction> = ActionsObservable.of<FluxStandardAction>({ type: 'SECOND' }, { type: 'FIRST' }, asap);
118+
const action$3: ActionsObservable<FluxStandardAction> = ActionsObservable.from<FluxStandardAction>([{ type: 'SECOND' }, { type: 'FIRST' }], asap);
119+
118120
console.log('typings.ts: OK');

0 commit comments

Comments
 (0)