From: Eduardo San Martin Morote Date: Sat, 15 May 2021 15:12:15 +0000 (+0200) Subject: docs: document custom state properties X-Git-Tag: v2.0.0-alpha.17~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39656b672956289705fd8500df1142d32d36e0ec;p=thirdparty%2Fvuejs%2Fpinia.git docs: document custom state properties --- 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