How to type-safely handle specific action returns in $onAction? #3050
-
Hey Pinia team! 👋 I'm wondering about a TypeScript type inference challenge with When using something like: assetStore.$onAction(({ name, after }) => {
after((ret) => {
if (name === "importAssetsFromPath") {
// How can I make TypeScript understand 'ret' is AssetImportResult here?
handleAssetsImported(ret as AssetImportResult);
}
});
}); Right now, I'm using a type assertion, but it feels a bit hacky. Any elegant TypeScript solutions or patterns you'd recommend for this scenario? Curious to hear your thoughts! 🤔 |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Oct 3, 2025
Replies: 1 comment
-
Putting the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zhristophe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Putting the
if
outside of theafter
should constrain the type as expected