Skip to content

How to type this in getters and actions defined outside a store? #983

Discussion options

You must be logged in to vote

Update: Partially Solved

I've managed to break down my store getters and actions into separate files with full TypeScript intellisense and type-checking support.

What's missing?

I've had to manually type the store getters. This is a small annoyance compared to the "define everything on the same file" approach, where Pinia automatically infers the type of getters and lets you access them type-safe from other getters or actions.

Using the ReturnType<typeof import('path/to/myStore.ts)['useMyStore']> syntax to automatically create a type with the store's computed type works wonders for actions but, unfortunately, does not work for getters (it causes a circular error). I don't know why it work…

Replies: 7 comments 8 replies

Comment options

You must be logged in to vote
3 replies
@mareszhar
Comment options

@jenstornell
Comment options

@mareszhar
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

You must be logged in to vote
3 replies
@angelhdzmultimedia
Comment options

@liquidvisual
Comment options

@angelhdzmultimedia
Comment options

Answer selected by mareszhar
Comment options

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

Comment options

You must be logged in to vote
0 replies
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
7 participants