Using the new Vue 3 Composition API, I have created a "store" for reactive data.
const state = reactive<State>({
accessToken: undefined,
user: undefined,
});
export default {
state: readonly(state),
}
When my app is created, I pass the store to all components:
const app = createApp(App)
.provide("store", store)
.use(IonicVue)
.use(router);
Finally, in a component/view, I inject the store to utilize it.
export default defineComponent({
name: "Home",
inject: ["store"],
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonButton,
},
computed: {
email() {
return this.store.state.user.email;
},
},
});
However, when using TypeScript, I encounter an issue with this.store
in the computed property email()
. The error message states:
Property 'store' does not exist on type 'ComponentPublicInstance<{}, {}, {}, { email(): any; }, {}, EmitsOptions, {}, {}, false, ComponentOptionsBase<{}, {}, {}, { email(): any; }, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, {}>>'
Everything works fine when removing the lang="ts"
attribute from the <script/>
tag, but the error persists. Any suggestions on how to resolve this or what it means?
Thank you in advance!