UNPKG

3.67 kBTypeScriptView Raw
1import { Action, ActionCreator, Creator } from '@ngrx/store';
2import { Observable, OperatorFunction, Operator } from 'rxjs';
3export declare class Actions<V = Action> extends Observable<V> {
4 constructor(source?: Observable<V>);
5 lift<R>(operator: Operator<V, R>): Observable<R>;
6}
7declare type ActionExtractor<T extends string | AC, AC extends ActionCreator<string, Creator>, E> = T extends string ? E : ReturnType<Extract<T, AC>>;
8/**
9 * 'ofType' filters an Observable of Actions into an observable of the actions
10 * whose type strings are passed to it.
11 *
12 * For example, if `actions` has type `Actions<AdditionAction|SubstractionAction>`, and
13 * the type of the `Addition` action is `add`, then
14 * `actions.pipe(ofType('add'))` returns an `Observable<AdditionAction>`.
15 *
16 * Properly typing this function is hard and requires some advanced TS tricks
17 * below.
18 *
19 * Type narrowing automatically works, as long as your `actions` object
20 * starts with a `Actions<SomeUnionOfActions>` instead of generic `Actions`.
21 *
22 * For backwards compatibility, when one passes a single type argument
23 * `ofType<T>('something')` the result is an `Observable<T>`. Note, that `T`
24 * completely overrides any possible inference from 'something'.
25 *
26 * Unfortunately, for unknown 'actions: Actions' these types will produce
27 * 'Observable<never>'. In such cases one has to manually set the generic type
28 * like `actions.ofType<AdditionAction>('add')`.
29 */
30export declare function ofType<AC extends ActionCreator<string, Creator>[], U extends Action = Action, V = ReturnType<AC[number]>>(...allowedTypes: AC): OperatorFunction<U, V>;
31export declare function ofType<E extends Extract<U, {
32 type: T1;
33}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, U extends Action = Action, V = T1 extends string ? E : ReturnType<Extract<T1, AC>>>(t1: T1): OperatorFunction<U, V>;
34export declare function ofType<E extends Extract<U, {
35 type: T1 | T2;
36}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, T2 extends string | AC, U extends Action = Action, V = ActionExtractor<T1 | T2, AC, E>>(t1: T1, t2: T2): OperatorFunction<U, V>;
37export declare function ofType<E extends Extract<U, {
38 type: T1 | T2 | T3;
39}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, T2 extends string | AC, T3 extends string | AC, U extends Action = Action, V = ActionExtractor<T1 | T2 | T3, AC, E>>(t1: T1, t2: T2, t3: T3): OperatorFunction<U, V>;
40export declare function ofType<E extends Extract<U, {
41 type: T1 | T2 | T3 | T4;
42}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, T2 extends string | AC, T3 extends string | AC, T4 extends string | AC, U extends Action = Action, V = ActionExtractor<T1 | T2 | T3 | T4, AC, E>>(t1: T1, t2: T2, t3: T3, t4: T4): OperatorFunction<U, V>;
43export declare function ofType<E extends Extract<U, {
44 type: T1 | T2 | T3 | T4 | T5;
45}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, T2 extends string | AC, T3 extends string | AC, T4 extends string | AC, T5 extends string | AC, U extends Action = Action, V = ActionExtractor<T1 | T2 | T3 | T4 | T5, AC, E>>(t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): OperatorFunction<U, V>;
46/**
47 * Fallback for more than 5 arguments.
48 * There is no inference, so the return type is the same as the input -
49 * Observable<Action>.
50 *
51 * We provide a type parameter, even though TS will not infer it from the
52 * arguments, to preserve backwards compatibility with old versions of ngrx.
53 */
54export declare function ofType<V extends Action>(...allowedTypes: Array<string | ActionCreator<string, Creator>>): OperatorFunction<Action, V>;
55export {};