State Snapshot of Setup Stores with Typescript #1905
Unanswered
TransferFunction
asked this question in
Help and Questions
Replies: 1 comment
-
You don't need to add the return type but if you really want to, you will have to type the return type with import { Ref } from 'vue'
interface CountState { count: Ref<number>, name: Ref<string> } |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have this situation where I use the Setup Stores syntax, but also try to add compatibility with Typescript. The problem occurs defining an interface
interface CountState { count: number, name: string }
and returning that interface type using the Setup Stores syntax
In this example (notice the returning of CountState), TS will throw an error, because
count
andname
are notnumber
andstring
types but,Ref<number>
andRef<string>
types. I tried to work around this by returning the value of the ProxiesBut that messes up the reactivity in components using the store values.
So to work around this I just wrote another interface for the returned state type and added a function to extract the values out of the Proxies to save a memento of the state.
Has anyone run into this problem?
Is there an elegant solution without changing syntax?
Beta Was this translation helpful? Give feedback.
All reactions