Performance: Type-safe stores with Pinia
MEDIUM IMPACT
This affects the JavaScript bundle size and runtime type checking, impacting page load speed and interaction responsiveness.
import { defineStore } from 'pinia'; import { ref, type Ref } from 'vue'; interface State { count: number; } export const useStore = defineStore('main', () => { const count: Ref<number> = ref(0); function increment() { count.value++; } return { count, increment }; });
import { defineStore } from 'pinia'; export const useStore = defineStore('main', { state: () => ({ count: 0 }), actions: { increment() { this.count++; } } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No type safety, no runtime checks | 0 | 0 | 0 | [OK] Good |
| Runtime type checks in actions | 0 | 0 | 0 | [X] Bad |
| Compile-time type safety with TypeScript | 0 | 0 | 0 | [OK] Good |