pinia-best-practices

Fix Pinia typing issues in Vue 3 + TypeScript projects with explicit getter return types.

1|Updated Apr 4, 2023
One-click install
npx skills add https://github.com/ElderEvil/falloutProject --skill pinia-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pinia-best-practices
Source: https://github.com/ElderEvil/falloutProject/tree/main/.agents/skills/pinia-best-practices
Command: npx skills add https://github.com/ElderEvil/falloutProject --skill pinia-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pinia stores in Vue 3 + TypeScript often suffer from typing issues, especially with storeToRefs, getters referencing this, and setup stores, leading to brittle typings and poor developer experience.

Core Features & Use Cases

  • Explicit getter return types to prevent ThisType and circular reference errors.
  • Typed setup stores and store patterns to improve type safety and autocomplete.
  • Debugging and resolving common Pinia typing issues in Vue 3 projects.

Quick Start

Apply this skill to resolve Pinia typing errors in a Vue 3 + TypeScript project.

Frequently Asked Questions about pinia-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix circular type errors in Pinia getters referencing this?

To fix circular type errors in Pinia getters, define explicit return types for your getters. This prevents ThisType inference issues and resolves brittle typings when getters reference the store context.

Why does storeToRefs lose type safety in my Vue 3 setup stores?

storeToRefs loses type safety in Vue 3 setup stores due to inadequate type inference. Applying typed setup store patterns aligns with Vue 3.5+ behavior to restore autocomplete and prevent type loss.

What is the best way to structure Pinia setup stores for TypeScript autocomplete?

The best way to structure Pinia setup stores for TypeScript autocomplete is using typed setup store patterns. This ensures proper type inference and aligns with Vue 3.5+ typing behavior for robust development.

Do I need explicit return types for all Pinia getters to improve type safety?

You need explicit return types for Pinia getters to improve type safety and prevent ThisType circular reference errors. This practice ensures stable typing and better developer experience in Vue 3.

Can I use this approach to resolve typing issues in existing Vue 3.5 projects?

Yes, you can use this approach to resolve typing issues in existing Vue 3.5 projects. It provides guidance to align with Pinia and Vue 3.5+ typing behavior, debugging and fixing common type errors.

When should I expect brittle typings with Pinia and TypeScript?

You should expect brittle typings with Pinia and TypeScript when using storeToRefs, getters referencing this, or setup stores without explicit types. These patterns often lead to poor developer experience and type inference failures.