question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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?

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
avxkimcommented, Aug 13, 2019

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.

1reaction
avxkimcommented, Aug 13, 2019

Both store and module exist in devtools, you mean getModule(myModule, store)? This doesn’t work, throws an error.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found