Skip to content

Commit

Permalink
fix: #785 fix type inference for produce incorrectly inferring promise (
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored Apr 25, 2021
1 parent 7a53828 commit 6555173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions __tests__/produce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/types/types-external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@ export interface IProduce {
initialState: State
): InferCurriedFromInitialStateAndRecipe<State, Recipe, false>

/** Promisified dormal producer */
<Base, D = Draft<Base>>(
base: Base,
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
listener?: PatchListener
): Promise<Base>

/** Normal producer */
<Base, D = Draft<Base>>( // By using a default inferred D, rather than Draft<Base> in the recipe, we can override it.
base: Base,
recipe: (draft: D) => ValidRecipeReturnType<D>,
listener?: PatchListener
): Base

/** Promisified dormal producer */
<Base, D = Draft<Base>>(
base: Base,
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
listener?: PatchListener
): Promise<Base>
}

/**
Expand Down

0 comments on commit 6555173

Please sign in to comment.