How to type Redux actions and Redux reducers in TypeScript?

后端 未结 20 2007
旧时难觅i
旧时难觅i 2020-12-13 03:39

What is the best way to cast the action parameter in a redux reducer with typescript? There will be multiple action interfaces that can occur that all extend a

20条回答
  •  伪装坚强ぢ
    2020-12-13 04:26

    To be fair there are many ways to type actions but I find this one very straight forward and has the less possible boilerplate as well (already discussed in this topic).

    This approach tries to type the key called "payload" of actions.

    Check this sample

提交回复
热议问题