Skip to content

Destructuring the store and type inference #406

Closed Answered by posva
Liwoj asked this question in Help and Questions
Discussion options

You must be logged in to vote

Doing

const user = toRef(store, 'user')
// or
const { user } = toRefs(store)

is correct but it seems like only the first one is correctly inferred while the second is not. This seems to be a bug on Vue types:

// this is the current version
declare function toRefs<T extends Data = Data>(obj: T): ToRefs<T>;
// this one works
declare function toRefs<T = Data>(obj: T): ToRefs<T>;

There might be an open PR already

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@posva
Comment options

Answer selected by posva
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants