欢迎各位兄弟 发布技术文章
这里的技术是共享的
'ofType' filters an Observable of Actions into an observable of the actions whose type strings are passed to it.
ofType<E extends Extract<U, {
type: T1;
}>, AC extends ActionCreator<string, Creator>, T1 extends string | AC, U extends Action = Action, V = T1>()
There are no parameters.
For example, if actions
has type Actions<AdditionAction|SubstractionAction>
, and the type of the Addition
action is add
, then actions.pipe(ofType('add'))
returns an Observable<AdditionAction>
.
Properly typing this function is hard and requires some advanced TS tricks below.
Type narrowing automatically works, as long as your actions
object starts with a Actions<SomeUnionOfActions>
instead of generic Actions
.
For backwards compatibility, when one passes a single type argument ofType<T>('something')
the result is an Observable<T>
. Note, that T
completely overrides any possible inference from 'something'.
Unfortunately, for unknown 'actions: Actions' these types will produce 'Observableactions.ofType<AdditionAction>('add')
.
Parameters
Returns
| ||||||||||
Parameters
Returns
| ||||||||||
Parameters
Returns
| ||||||||||
Parameters
Returns
| ||||||||||
Fallback for more than 5 arguments. There is no inference, so the return type is the same as the input - Observable
Parameters
Returns
We provide a type parameter, even though TS will not infer it from the arguments, to preserve backwards compatibility with old versions of ngrx. | ||||||||||
Parameters
Returns |