store state Object is of type unknown
See original GitHub issue/src/middlewares/auth.ts file:
import store from '@/store'
export default {
guest(): void {
if (store.state.auth.authenticated === false) {
// do some action
}
}
}
/src/store.ts file:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
auth
}
})
/src/store/auth.ts:
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
@Module
export default class Auth extends VuexModule {
public authenticated: boolean = false
}
However i’m getting TS error: Object is of type ‘unknown’
Then my npm run build fails. How can i type store.state.auth.authenticated
so this error would disappear?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Vuex - store state Object is of type unknown - Stack Overflow
if i change store.state.auth.authenticated to store.state then compiler stops complaining, i think its related to my store auth.ts file, i ...
Read more >Object is of type 'unknown' Error in TypeScript | bobbyhadz
The "Object is of type unknown" error occurs when we try to access a property on a value that has a type of...
Read more >[Solved]-Vuex - store state Object is of type unknown-Vue.js
Coding example for the question Vuex - store state Object is of type unknown-Vue.js.
Read more >Usage With TypeScript - Redux
Inferring these types from the store itself means that they correctly update as you add more state slices or modify middleware settings.
Read more >How to type an object in Pinia state. Why unknown - r/vuejs
I have a store with a team property that needs to be of type Object. I have created an Interface called TeamInterface though...
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
If i completely omit modules thing just like in this example: https://github.com/xieguangcai/vue-order-admin, then i’m getting error about unknown actions… So much pain.
Both store and module exist in devtools, you mean
getModule(myModule, store)
? This doesn’t work, throws an error.