typescript-fsa
from redux-observable を TypeScript で使う
typescript-fsa
https://github.com/aikoven/typescript-fsa
FSA: Flux Standard Action
typeをもつプレーンオブジェクト
Action の型も定義して、ActionCreator の型も定義して…ってするのは非常にしんどい
だったら ActionCreator そのものに型推論できる情報を与えてやればいいのでは?というアプローチ
https://triplet-assets.s3.amazonaws.com/typescript/typescript_fsa_reducer.gif
https://www.triplet.fi/blog/type-safe-flux-standard-actions-fsa-in-react-using-typescript-fsa/
©︎ Tatu
isTypeというヘルパー関数が型推論の鍵を握っている
TypeScript の Type Guard を使って型ヒントを出せる
ActionCreator を引数に与える => Action の型を推論する => Payload の型がわかる
自分で Action の型を定義する必要がなくなり、ボイラープレートの量が激減する