Error: this.$store does not exist on type class. (Vue 3 + TypeScript)
See original GitHub issueInfo
- Platform: Ubuntu 20.04 (WSL2, Ubuntu Budgie)
- Vetur version: 0.27.3
- VS Code version: 1.49.1
Problem
Reproducible Case
- Use the Vue CLI to create a Vue 3 project with TypeScript using class component style syntax.
- Go into the store and create any state object.
- In your class (happens in methods, computed, anything), call
this.$store
, - See vetur complain that
this.$store
does not exist on the class.
I followed this link: https://discordapp.com/channels/325477692906536972/568037134968160256/756604272484941856 after speaking with some people on the Vue discord, and added the vuex-shim.d.ts
file which did fix it but it stopped working again, I swapped it to use Store<any>
instead.
See my shim:
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'
declare module '@vue/runtime-core' {
// Declare your own store states.
interface State {
count: number
}
interface ComponentCustomProperties {
$store: Store<any>
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Vue.js 3 and typescript : Property '$store ... - Stack Overflow
$store doesn't seem to be accessible, despite following the Vue 3 instructions. ERROR in src/components/FlashMessages.vue:28:25 TS2339: Property ...
Read more >♂️ ♀️ Vue 3 error with using TypeScript: property X does ...
♂️ ♀️ Vue 3 error with using TypeScript: property X does not exist on type 'EventTarget'. #vue #typescript #showdev #beginners ...
Read more >Vue.js 3 and typescript : Property '$store' does not exist on ...
Coding example for the question Vue.js 3 and typescript : Property '$store' does not exist on type 'ComponentPublicInstance-Vue.js.
Read more >$store property not found by TypeScript - Get Help - Vue Forum
TypeScript complains when my computed property function calls this.$store . Property '$store' does not exist on type 'Vue'.
Read more >How to use Vue 3 with TypeScript - LogRocket Blog
Build an example Vue app in TypeScript with class-based components, ... Vue is flexible, so users are not forced to use TypeScript.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The same error here using Quasar Framework, after upgrade from Quasar v1 (Vue 2) to Quasar v2 (Vue 3)
@ngekoding or anyone else looking for a solution to this. I spent hours looking for a solution and the following code worked for me: First, when mounting the app, create a global property for
$store
:then I created this file in src folder:
I don’t know if it could help, but I stopped and ran the project again (
yarn serve
) More info here