Skip to content

Types ​

Pinia ​

The Pinia instance type (returned by createPinia()).

MemberSignatureNotes
use(plugin: PiniaPlugin) => Piniaregister a plugin, chainable
install(app: any) => voidapp.use(pinia) entry (reliable on Web only; use setActivePinia on native)

PiniaPlugin ​

uts
export type PiniaPlugin = (ctx: PiniaPluginContext) => void

Plugin function type. UTS constraint: returns void (no object merging into the store); hook logic goes through the context.

PiniaPluginContext ​

uts
export type PiniaPluginContext = {
  pinia: Pinia,
  store: any,
  storeId: string
}
FieldNotes
piniathe current Pinia instance
storethe newly created store instance (any; narrow with as at the use site)
storeIdthe store id

Unsubscribe ​

uts
export type Unsubscribe = () => void

Unsubscribe handle (the return shape of per-field watch).

Store type convention ​

Store types are user-defined type aliases with explicit annotations (object literals can only be assigned to type aliases):

uts
export type CounterStore = {
  count: Ref<number>,                 // state: Ref<T>
  doubleCount: ComputedRef<number>,   // getter: ComputedRef<T>
  increment: () => void               // action: arrow function
}

WARNING

ComputedRef must be imported explicitly: import type { ComputedRef } from 'vue' (not globally injected). Ref is injected, but importing both explicitly is recommended.

Released under the MIT License.