Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #785 fix type inference for produce #786

Merged
merged 1 commit into from Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/produce.ts
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
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