Add typings for the Vuex store
Add typings for the Vuex store
Pull Request Type
- [x] Feature Implementation
- [x] Developer Improvement
Description
I know we plan to eventually switch to Pinia, which has first-class TypeScript support out-of-the-box but until then I thought I would help us out a bit. I've been working on this on and off for a few weeks now and am now finally happy enough with it to create this pull request.
VueX like Vue 2 was designed before everyone realised that auto-complete and type safety are unmissable development aides, so neither was designed with TypeScript in mind. For Vue 2 they've done a very good job of creating mostly usable types, despite the Options API being extremely difficult to type (some of the types they have built are really complex), for Vuex however there is very limited typing out of the box.
Most of the guides online recommended writing all the types for your Vuex store by hand and maintaining them by hand, which I thought was a bit ridiculous to do for FreeTube as we don't do any type checking at the moment and are probably going to switch to Pinia at some point in the near future anyway. So I built this "magical" thing that infers most of the stuff automatically for you.
Caveats:
- Due to bugs in Vue 2's types, it doesn't add anything in
methodstothis, unfortunately that means that despitemapActionsandmapMutationsreturning the correct types, the mapped actions and mutations won't show up onthis, like all other methods. - Even though this mostly works okay, there are some issues that can crop up due to everything being inferred and typescript getting confused, one such example is that we can't add typings to the side-effect handlers in the settings store module, otherwise TypeScript complains that the state and getters reference themselves.
Screenshots
Testing
Try it out in your editor! (Please read the caveats section above if you haven't already)
Desktop
- OS: Windows
- OS Version: 10
- FreeTube version: b2fe59d331289e0365f67e04e0186e17374b8d1c
I use RubyMine & see auto complete but not the return types of getters
Could be RubyMine issue though
This pull request has conflicts, please resolve those before we can evaluate the pull request.
Conflicts have been resolved. A maintainer will review the pull request shortly.
This pull request has conflicts, please resolve those before we can evaluate the pull request.
Closing as it seems unlikely that this will get merged and hopefully we'll switch to Pinia soon which has much better typing support out of the box.