When using mapGetters
, TypeScript has no visibility into what the getters being bound to the Vue component, so it throws errors. Example:
import Vue from 'vue';
import { mapActions, mapGetters } from 'vuex';
export default Vue.extend({
computed: {
...mapGetters('ui', ['navCollapsed']),
minimizerIconClass(): string {
return `fa${this.navCollapsed ? '' : 'r'} fa-window-maximize`;
},
},
TypeScript is yelling about this.navCollapsed
:
TS2339: Property 'navCollapsed' does not exist on type 'CombinedVueInstance<Vue, {}, { openMobileMenu(): void; }, { minimizerIconClass: string; }, Readon...'.
How do I fix this? The only workaround I can come up with is to not use mapGetters()
.
this
parameter:minimizerIconClass(this: ComponentTypeHere)
. (It exists only at compile time and stripped out during compilation) – PrimaComponentTypeHere
would be? (sorry, pretty new to TypeScript) – Predikant{ navCollapsed: boolean }
in this specific example. (Need more info, not sure wherenavCollapsed
comes from) – PrimanavCollapsed
is being injected bymapGetters()
. – Predikant