From: Eduardo San Martin Morote Date: Fri, 9 Apr 2021 18:35:57 +0000 (+0200) Subject: feat(types): fail on async patch X-Git-Tag: v2.0.0-alpha.13~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c254a8abc73d7e2589acbffe432a33f985c1003d;p=thirdparty%2Fvuejs%2Fpinia.git feat(types): fail on async patch --- diff --git a/src/types.ts b/src/types.ts index bc81a256..a7a5a2a4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -76,9 +76,12 @@ export interface StoreWithState { * Sets or arrays and applying an object patch isn't practical, e.g. appending * to an array. * - * @param stateMutator - function that mutates `state` + * @param stateMutator - function that mutates `state`, cannot be async */ - $patch(stateMutator: (state: S) => void): void + $patch void>( + // this prevents the user from using `async` which isn't allowed + stateMutator: ReturnType extends Promise ? never : F + ): void /** * Resets the store to its initial state by building a new state object. diff --git a/test-dts/store.test-d.ts b/test-dts/store.test-d.ts index 8105e2f7..5350092b 100644 --- a/test-dts/store.test-d.ts +++ b/test-dts/store.test-d.ts @@ -21,3 +21,11 @@ store.nonExistant // @ts-expect-error store.nonExistant.stuff + +// @ts-expect-error cannot return a value +store.$patch(async () => {}) +store.$patch(() => {}) +store.$patch(() => { + // return earlier + return +})