]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: document custom state properties
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 15:12:15 +0000 (17:12 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 15:15:18 +0000 (17:15 +0200)
docs/core-concepts/plugins.md

index 19109a4d8b52ee5f952e3dd9bdc4feee111fc174..f180d887a10131bf0c5a6bf31ed5202f1a03e473 100644 (file)
@@ -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<State> {
+    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