From: Eduardo San Martin Morote Date: Wed, 12 May 2021 09:29:07 +0000 (+0200) Subject: fix(types): patch should unwrap refs X-Git-Tag: v0.5.0~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9668167fcdff2da2733fef92c941b1eedf13233a;p=thirdparty%2Fvuejs%2Fpinia.git fix(types): patch should unwrap refs --- diff --git a/src/types.ts b/src/types.ts index 21965263..a9a043b9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -138,7 +138,7 @@ export interface StoreWithState { * Applies a state patch to current state. Allows passing nested values * @param partialState - patch to apply to the state */ - $patch(partialState: DeepPartial): void + $patch(partialState: DeepPartial>): void /** * Group multiple changes into one function. Useful when mutating objects like @@ -147,7 +147,7 @@ export interface StoreWithState { * * @param stateMutator - function that mutates `state`, cannot be async */ - $patch void>( + $patch) => void>( // this prevents the user from using `async` which isn't allowed stateMutator: ReturnType extends Promise ? never : F ): void diff --git a/test-dts/state.test-d.ts b/test-dts/state.test-d.ts index 671e2bcd..ed2a975a 100644 --- a/test-dts/state.test-d.ts +++ b/test-dts/state.test-d.ts @@ -38,6 +38,11 @@ const useStore = defineStore({ expectType(this.$state.counter) expectType(this.double) expectType(this.counter) + + this.$patch({ counter: 2 }) + this.$patch((state) => { + expectType(state.counter) + }) }, }, })