-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Typescript support in a few places #7
Comments
OverviewSo it seems the root cause of our various problems is simply that TS support for Vue CLI 2 and Vuex 3 (the state management module) is lacking. When Vue CLI 3 and Vuex 4 are released (supposed to happen this summer), there will be full TS support. Below are the options I see and the one that seems best to me. Note that as far I can tell from testing, these tradeoffs only apply to OptionsNo ChangesKeep our current architecture. In this approach, we will turn off the Pros:
Cons:
Change Component APIRight now we use what's called the "Options API" in Vue components. I initially went with this because it's a very popular and familiar API. If we switch to the "Composition API", this will remove most lint errors in the This happens because Vuex 3 does not properly support typing, as explained in this issue. Pros:
Cons:
I tested this out on a small project this weekend, and you can see the code here. Since our current project is fairly simple, I think we can migrate to the new format over in about 4 hours, maybe 6 if things go wrong. Change Component API, and use our own storeThis builds upon the above approach. To work around the lack of type support in Vuex 3, some people opt to write their own state management module. I think this is probably not worth the development effort, but wanted to mention it for completeness. Pros:
Cons:
|
Sorry for butting in here, I was just reading the Vuex issue thread you linked and clicked on the referenced comments to see what other repos were saying and doing about it. I've been doing Vue + TS for a while so I wanted to offer my two cents:
Hopefully this is useful, and good luck with your project 👍 |
Thanks @Hawxy, really appreciate your help here—this is super helpful information! I certainly didn't realize how messy the Options API would be when we started this. I've been using Vue for a while but this is the first time attempting TS integration, and it's definitely been trickier to setup than I expected.
These packages look great! Definitely will look into them. When trying the composition API it seems the only remaining type issues were the fact that the store was of the
This is good to know—I hadn't realized this was the most popular approach for TS integration. Are there any differences to be aware of with the class-style components vs. composition API? I'm mostly curious in terms of TS support, though I haven't used the class style components so am wondering if there's any other tradeoffs to consider. |
I'll delegate this to the Composition RPC: I personally find class-style components a very natural way of building components, since you're just writing functions, properties and getters within a class as you would in other OO languages (my background is C#) without needing to conform with vue-specific object syntax. There are definitely edge-cases with its type safety but it generally works well for myself and my team (and I'd rather not force everyone to learn the Comp API right now). The Composition API is the future of Vue component building, but the somewhat steeper learning curve compared to Options/Class-Component means the other component styles will be sticking around for a while. It's up to you if you want to use it now or wait for Vue 3 to release and the ecosystem to catch up. I'd probably just recommend spiking a component using both styles and seeing what yourself and your team are the most comfortable with. |
Awesome, this is all really helpful info. Thanks so much for helping us get pointed in the right direction! |
Files lacking Typescript support or that need TS updates:
components.js
should becomponents.ts
BaseInput.vue
watcher should be updated to removeeslint-disable
this.$router.push({...})
currently useeslint-disable-line
to avoidno-unsafe-member-access
notifyUser
useeslint-disable-line
to avoidno-unsafe-call
The text was updated successfully, but these errors were encountered: