]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(types): patch should unwrap refs
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 May 2021 09:29:07 +0000 (11:29 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 12 May 2021 09:29:07 +0000 (11:29 +0200)
src/types.ts
test-dts/state.test-d.ts

index 49165d7b83d3fa5d7d980623a4de0054f974c50c..4c21fa7056d98131160edad8324ac794b3890b27 100644 (file)
@@ -151,7 +151,7 @@ export interface StoreWithState<Id extends string, S extends StateTree> {
    *
    * @param partialState - patch to apply to the state
    */
-  $patch(partialState: DeepPartial<S>): void
+  $patch(partialState: DeepPartial<UnwrapRef<S>>): void
 
   /**
    * Group multiple changes into one function. Useful when mutating objects like
@@ -160,7 +160,7 @@ export interface StoreWithState<Id extends string, S extends StateTree> {
    *
    * @param stateMutator - function that mutates `state`, cannot be async
    */
-  $patch<F extends (state: S) => void>(
+  $patch<F extends (state: UnwrapRef<S>) => void>(
     // this prevents the user from using `async` which isn't allowed
     stateMutator: ReturnType<F> extends Promise<any> ? never : F
   ): void
index 671e2bcd13de0f64e7921f2a49ecaef07a4f3997..ed2a975abf68dc20790b876fb5b687c298532ccd 100644 (file)
@@ -38,6 +38,11 @@ const useStore = defineStore({
       expectType<number>(this.$state.counter)
       expectType<number>(this.double)
       expectType<number>(this.counter)
+
+      this.$patch({ counter: 2 })
+      this.$patch((state) => {
+        expectType<number>(state.counter)
+      })
     },
   },
 })