Identical to isType
except it is exposed as a bound method of an action
creator. Since it is bound and takes a single argument it is ideal for
passing to a filtering function like Array.prototype.filter
or
RxJS's Observable.prototype.filter
.
const somethingHappened =
actionCreator<{foo: string}>('SOMETHING_HAPPENED');
const somethingElseHappened =
actionCreator<{bar: number}>('SOMETHING_ELSE_HAPPENED');
if (somethingHappened.match(action)) {
// action.payload has type {foo: string}
}
const actionArray = [
somethingHappened({foo: 'foo'}),
somethingElseHappened({bar: 5}),
];
// somethingHappenedArray has inferred type Action<{foo: string}>[]
const somethingHappenedArray =
actionArray.filter(somethingHappened.match);
Creates action with given payload and metadata.