Skip to content

How to use Typing new state in the state type defination? #788

Discussion options

You must be logged in to vote

The docs you linked are referring to plugins and don't seem related to what you're trying to accomplish here in defining a store.

A slightly better way to accomplish what you're trying to do is the following:

const userStore = defineStore({
  id: 'user',
  // type the return of state instead
  state: (): UserProperties => ({
    name: '',
    data: {}, // this will now show a type error
  }),
});

If you do this, according to your example above you will see a type error because you define email as a property in data but aren't providing it.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@r-priyam
Comment options

@dbarjs
Comment options

Answer selected by r-priyam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants