Skip to content

Confused with returning Ref<T> as a type to a Pinia state #485

Discussion options

You must be logged in to vote

The state should return a plain object (it can be a reactive object as well). It cannot be a Ref. So maybe do:

state() {
        return {
           user: useStorage<Authentication.UserProfile>(
            "user",
            { accessToken: "", displayName: "", photoUrl: "", emailAddress: "" },
            localStorage);
  }
    },

The problem is that from a typing perspective, it will think the type of this.user is a ref while in practice it isn't. I think we could unwrap refs automatically in pinia types

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@philippedasilva-orizone
Comment options

@posva
Comment options

@philippedasilva-orizone
Comment options

@posva
Comment options

@philippedasilva-orizone
Comment options

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