3 ms·
How did you get typescript working properly with redux? I never could figure out how to get proper types in my reducers or HMR to work.
by geewee 10y ago
How did you get typescript working properly with redux? I never could figure out how to get proper types in my reducers or HMR to work.
- tomduncalf 10y agoYou end up doing a bit of explicit casting in places to ensure type safety, but it works. Little discussion I had about this with someone on Twitter which may or may not be relevant: https://twitter.com/tomduncalf/status/804002710878044160 https://twitter.com/tomduncalf/status/804002710878044160 I should write a blog post about Redux and Typescript - it would be good to know which bits you are struggling with. HMR works fine with Typescript, you do need to use Babel as well though. This post I wrote should get you up and running: http://blog.tomduncalf.com/posts/setting-up-typescript-and-react/ http://blog.tomduncalf.com/posts/setting-up-typescript-and-r..., it is a little outdated (1.9 vs 2.1) but I don't think any major changes should be needed to make it work with newer versions. Unfortunately, HMR (v3 beta) doesn't play nice with react-router as far as I can tell, so I have given up on it for now. I really miss it so I hope someone knowledgable finds time to focus on getting it working better soon!
- geewee 10y agoThat's a really helpful blog post, actually. I thin the general pain points are the same as in your twitter discussion - the reducers quickly start feeling clunky with explicit casts or using two lines to export a constant for the switch statement. It's obviously a possibility to just forego type-safety in that part, but it'd be a shame. Another general pain point (apart from the fact that a lot of the guides you find seem reasonably outdated) is the general build setup. Your guide seems really good, but generally setting up react redux and typescript is a bit of a jungle. If you do end up writing a post, please let me know!
- Zalastax 10y agoI've not written any blog about it but I have it working in a repo [1]. The webpack config and src/model are what's most interesting for you :) To sum it up: combineReducers is templated so make an interface for your state (this is wonderful). HMR works with react-hot-loader 3 and without babel, but the documentation is lacking. [1]: https://github.com/Zalastax/openschedule https://github.com/Zalastax/openschedule
- geewee 10y agoThis is nice, thanks a bunch!