Store with array of compostables - TS interface error #2842
Unanswered
gnom1gnom
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
in my project I use a Pinia store with an array of several types of composables with a common interface.
I figured out this is the easies way implement reactive behavior for each instance of a particular composable.
(What as I understand is supported by Pinia (Dealing with Composables)
I will illustrate this with a simple example (with just one composable for simplicity).
Go here to see it live https://stackblitz.com/edit/github-5e44kz
Suppose I have an animal composable
Then the Animal interface for this composable is
But when I try to use this interface with a store, like so:
I get a TS warning
But if I change the deffinition of an Animal to
Then I will get complains in the composable
Finally if I don't specify the return type of the composable,
Then I get an error on
I think the whole problem comes from the fact that Pinia is unwrapping refs of the composable.
If there a solution that satisfies both composable and store type declaration?
Beta Was this translation helpful? Give feedback.
All reactions