Skip to content

Commit 6555173

Browse files
authored
fix: #785 fix type inference for produce incorrectly inferring promise (#786)
1 parent 7a53828 commit 6555173

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

__tests__/produce.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ it("infers async curried", async () => {
734734
})
735735
assert(res, _ as State | undefined)
736736
}
737+
{
738+
// as any
739+
const res = produce(base as State, draft => {
740+
return nothing as any
741+
})
742+
assert(res, _ as State)
743+
}
737744
{
738745
// nothing not allowed
739746
// @ts-expect-error

src/types/types-external.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,19 @@ export interface IProduce {
211211
initialState: State
212212
): InferCurriedFromInitialStateAndRecipe<State, Recipe, false>
213213

214-
/** Promisified dormal producer */
215-
<Base, D = Draft<Base>>(
216-
base: Base,
217-
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
218-
listener?: PatchListener
219-
): Promise<Base>
220-
221214
/** Normal producer */
222215
<Base, D = Draft<Base>>( // By using a default inferred D, rather than Draft<Base> in the recipe, we can override it.
223216
base: Base,
224217
recipe: (draft: D) => ValidRecipeReturnType<D>,
225218
listener?: PatchListener
226219
): Base
220+
221+
/** Promisified dormal producer */
222+
<Base, D = Draft<Base>>(
223+
base: Base,
224+
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
225+
listener?: PatchListener
226+
): Promise<Base>
227227
}
228228

229229
/**

0 commit comments

Comments
 (0)