Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vuex] state field "foo" was overridden by a module with the same name at "foo" #1652

Closed
mspoulsen opened this issue Nov 28, 2019 · 4 comments
Closed

Comments

@mspoulsen
Copy link

@mspoulsen mspoulsen commented Nov 28, 2019

Version

3.1.2

Reproduction link

https://gist.github.com/mspoulsen/f3a67e22a76ba124e606a0beae597974

Steps to reproduce

Create a minimal store using the gist.
Then try to access store.state.foo

Result: We get Typescript error: Property 'foo' does not exist on type 'RootState'.

What is expected?

A Typescript error is expected

What is actually happening?

We get the Typescript error and that is the problem


How would I be able to access store.state.foo without adding foo to RootState? And if I do I get this warning in 3.1.2:
[vuex] state field "foo" was overridden by a module with the same name at "foo"

@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 28, 2019

Essentially duplicate of #1267

You can add your module state in RootState and cast the root state value to any as a work around.

@ktsn ktsn closed this Nov 28, 2019
@mspoulsen

This comment has been minimized.

Copy link
Author

@mspoulsen mspoulsen commented Nov 28, 2019

That wouldn't make the warning go away, right?

@ktsn

This comment has been minimized.

Copy link
Member

@ktsn ktsn commented Nov 28, 2019

Yes it will go away.

interface RootState {
  foo: {} // declare your module state
}

const rootState: any = {
  
}

const storeConfig: StoreOptions<RootState> = {
  modules: {
    foo: {}
  },
  state: rootState
}

const store: Store<RootState> = new Vuex.Store(storeConfig)
@mspoulsen

This comment has been minimized.

Copy link
Author

@mspoulsen mspoulsen commented Nov 28, 2019

That works, thanks! Can't wait for Vue3 and Typescript just working everywhere 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.