Closed
Description
The current "Usage with TypeScript" page has multiple issues, and we should rework it. When that page was written in 2018-ish, I still didn't know TS yet. So, I couldn't offer any meaningful feedback on the contents. Now that I actually have a decent TS background, I can see that there's problems:
- The page shows patterns like hand-written action creators and creating unions of action types, which are both patterns we now discourage ( https://phryneas.de/redux-typescript-no-discriminating-union )
- It should show RTK as the default approach first, and hand-writing individual pieces as a fallback
- We have mismatched information between the three different TS usage pages in our docs (Redux core, React-Redux, and RTK), and we should harmonize them to have the same advice in all places
- We should better explain things like extracting the custom store
Dispatch
type to allow correctly dispatching thunks. (This is by far one of the most common questions I see lately, and I'm not sure how to easily address it through code, so we need to highlight the importance of this for thunk usage.) - Per Root state properties being typed as never with redux 4.0.5. #3690 (comment) , we don't mention the
Reducer
type - Along with all that, the CodeSandbox example link is apparently busted anyway.
and I'm sure there's some other improvements we could make as well.
The recently updated "TS Quick Start" page in the RTK docs would be a good starting point for "here's what to do":
https://redux-toolkit.js.org/tutorials/typescript
and then we can give more details for specific situations after that.