-
Notifications
You must be signed in to change notification settings - Fork 429
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
Property does not exist on the type in vue-class-component #360
Comments
But why to write the property in two places? :( |
You write it in one place, within the class body
this is the correct, supported and documented The decorator allows passing various component options to be merged in with the component, but those options do not become typesafe by themselves, because, as I mentioned previously, a decorator cannot modify the type it decorates. So while your approach works, it does not add typesafety, which, arguably, is the whole point of |
@ReinisV I just give example that getter in component is not working with typescript. The real reason is to use |
Honestly, I don't know how to work regular old Vuex and it's mapXXX methods in with the I'm not saying it is impossible, I've just never tried, because I use class based Vuex wrappers together with my class based Vue wrapper :) My favorite is vuex-simple. |
Not true, now that I think of it, I did write my own set of mapXXX methods specifically to work with any kind of Vuex (I used them with the same vuex-simple, but they could be used with vanilla Vuex too, they just would not provide typesafety). The logic was that you have a mapXXX method, that you pass a callback that accesses the specific state/getter/action. That method would then read that callback's code, determine the name of that field to get, and store it in the field on the instance. Then, the custom decorator reads that field name from the instance, and then replaces it with its own getter that is a wrapper for regular old vanilla vuex instance. It does the replacing on an per-instance basis by hooking it's logic into the Alas, this was a long time ago and that code was proprietary, so even if I had access to it, I couldn't share it. Thanks capitalism! when it was used, it looked something like this
|
Off the books, yeah I think it is better to do that. As you most likely already know, Vue3 promises to have the new functional/hook/whatever api, which will be a lot better for both TypeScript typesafety and Vue development overall, so there won't be much use for classes in Vue component defintions looking into the future. If I'd be working on new projects, I'd just tide myself over using Vue (or JS for that matter) has never quite fit the box (the box, in this case, is |
This is because decorator cannot change the class instance type. You have to declare the property type by yourself or use some decorator like vuex-class to map getters on class properties. |
I created new vue with typescript application using latest @vue/cli (v3).
When I use component decorator from
vue-class-component
withcomputed
/props
/methods
, I got an error:Here my code:
But according to the example it should be working fine. How do I fix this?
The text was updated successfully, but these errors were encountered: