From 6555173838f575d48a3fcb825c5a7d1953573a11 Mon Sep 17 00:00:00 2001 From: hardfist Date: Sun, 25 Apr 2021 22:50:28 +0800 Subject: [PATCH] fix: #785 fix type inference for produce incorrectly inferring promise (#786) --- __tests__/produce.ts | 7 +++++++ src/types/types-external.ts | 14 +++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/__tests__/produce.ts b/__tests__/produce.ts index efc43703..e034a8a9 100644 --- a/__tests__/produce.ts +++ b/__tests__/produce.ts @@ -734,6 +734,13 @@ it("infers async curried", async () => { }) assert(res, _ as State | undefined) } + { + // as any + const res = produce(base as State, draft => { + return nothing as any + }) + assert(res, _ as State) + } { // nothing not allowed // @ts-expect-error diff --git a/src/types/types-external.ts b/src/types/types-external.ts index c8ef906b..7cb01a76 100644 --- a/src/types/types-external.ts +++ b/src/types/types-external.ts @@ -211,19 +211,19 @@ export interface IProduce { initialState: State ): InferCurriedFromInitialStateAndRecipe - /** Promisified dormal producer */ - >( - base: Base, - recipe: (draft: D) => Promise>, - listener?: PatchListener - ): Promise - /** Normal producer */ >( // By using a default inferred D, rather than Draft in the recipe, we can override it. base: Base, recipe: (draft: D) => ValidRecipeReturnType, listener?: PatchListener ): Base + + /** Promisified dormal producer */ + >( + base: Base, + recipe: (draft: D) => Promise>, + listener?: PatchListener + ): Promise } /**