Currently, I'm utilizing typescript alongside vue in my project.
Within the app structure, there exists a service
that acts as a global entity for all sub-components.
I stumbled upon this native solution provided by Vue JS, which facilitates injecting this property into child components.
In the main.ts file:
const service = new MyService(...);
new Vue({
router,
provide() { return { service }; } // providing the service for injection
render: h => h(App),
}).$mount("#app");
For any typescript vue component:
import Vue from "vue";
export default Vue.extend({
inject: ["service"], // injecting the service
mounted() {
console.log(this.service); // access to this.service is available
},
});
By following this method, I am successfully able to acquire the injected service
within my Child components.
However, an error message is being displayed:
Error - 'Property 'service' does not exist on type 'CombinedVueInstance < Vue, {}, {}, {}, Readonly < Record < never, any > > >'.'
What steps can be taken to rectify this typescript compilation error?