From 39656b672956289705fd8500df1142d32d36e0ec Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sat, 15 May 2021 17:12:15 +0200 Subject: [PATCH] docs: document custom state properties --- docs/core-concepts/plugins.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/core-concepts/plugins.md b/docs/core-concepts/plugins.md index 19109a4d..f180d887 100644 --- a/docs/core-concepts/plugins.md +++ b/docs/core-concepts/plugins.md @@ -264,6 +264,22 @@ declare module 'pinia' { } ``` +### Typing new state + +When adding new state properties (to both, the `store` and `store.$state`), you need to add the type to `PiniaCustomStateProperties` instead. Differently from `PiniaCustomProperties`, it only receives the `State` generic: + +```ts +import 'pinia' + +declare module 'pinia' { + export interface PiniaCustomStateProperties { + hello: string + } +} +``` + +### Typing new creation options + When creating new options for `defineStore()`, you should extend the `DefineStoreOptions`. Like `PiniaCustomProperties`, it also exposes all the generics that define a store, allowing you to limit what can be defined. For example, you can une the names of the actions: ```ts -- 2.47.2