DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Discussion on: Redux 4 + TypeScript: A type-safe approach

Collapse
barryblando profile image
Barry⚑ • Edited on

Any chance for a post like this but using that approach(RxJS + Redux-Observables)?

Collapse
lexlohr profile image
Alex Lohr

Unfortunately, I currently haven't got the time to do all of this, so here's only a small overview of the differences:

It looks a bit like the example in redux-observable.js.org/docs/basic..., but instead of ofType(...), you are using isActionOf(...) from typesafe-actions, which requires you to define the action with createAction from the same package as already shown in this guide.

One thing that I would also add for convenience is that you can aggregate the action types automatically using the package utility-types:

// ./mytypes.ts
import { $call } from 'utility-types';
import * as MyActions from './actions';

// ... insert your other types here

const allActions = Object.values(MyActions).map($call);
export type MyAction = typeof allActions[number];

This way you automatically get the types for all your actions, which then are also checked when you use them inside your epics.