vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 429 forks source link

[v8] Use watch and provide inject in type safe way #511

Open nicolidin opened 3 years ago

nicolidin commented 3 years ago

This issue references the answer you @ktsn wrote about the usage of watch and provide/inject in a safe way:

ktsn :" You can access this via both @Options and this.$watch already. As for provide/inject, I'm considering an API to achieve it in type safe way currently. Also, you can still use vue-property-decorator if you prefer it since the author said he is going to update it for Vue 3.

Originally posted by @ktsn in https://github.com/vuejs/vue-class-component/issues/468#issuecomment-706149254 "

Indeed, it could be more safe , readable and typescript way to use for the this.$watch parameter directly the symbol of the property to watch instead of the string corresponding to the symbol we want to watch.

count = 0;

created() {
  this.$watch("count", () => {
    console.log(count updated);
  });
}

So for example, instead of the above "count" string, it would be really interesting to use directly the count symbol.

-- In the referenced issue you @ktsn said you were about to work on this implementation, how is it going on? It would be a real type system feature improvement, hope you can do that.

nicolidin commented 3 years ago

Furthermore provide is not accessible through this.$provide and only accessible through the @Options decorator, it would be firstly interesting to allow access to provide and inject through this.$. in a type-safety way. Moreover, Provide and Inject don't have any type-safety checking and act as they have an any type. (It might need another issue)