RxJS自体はTypeScriptと相性は良いと思います。
RxJS自体がTypeScriptで作られているわけですし。
じゃあredux-observableはどうなんだろうとなりますが
意外とそうでもないです。
とくにofTypeがtypeScriptと相性が良くないです。
'typescript-fsa'がいい感じなので、対応してみました。
以下のコマンドでインストールします
yarn add typescript-fsa-redux-observable
使いかたはこんな感じ
import { State } from 'reducers';
import { Epic, combineEpics } from 'redux-observable';
import * as actions from '../actions';
import * as Rx from 'rxjs';
import 'typescript-fsa-redux-observable';
export const loadAccountEpic: Epic<{}, State> =
(actions$, state) => actions$.ofAction(actions.loadAccount.started)
.mergeMap((action) => {
return fetchAccount$(action.payload.accountID)
.map(resp => actions.loadAccount.done({
params: {accountID: resp.id},
result: [resp]
}))
.catch(err => Rx.Observable.of(actions.loadAccount.failed({
params: {accountID: 0},
error: err
})));
});
epicを書く時にofTypeではなくofActionを使いactionCreatorを指定できます。
ofTypeのときとは違いactionの型を認識できるので前より楽になりました。
こんな感じで型がわかるわけです。