Skip to content
Myr

fix: #785 fix type inference for produce incorrectly inferring promise (#786)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by hardfist · committed by GitHub · parent 7a53828 · Browse files · 2 files+14 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−7 removed

  • tests:+7 added−0 removed
  • other:+7 added−7 removed

2 files+14 added−7 removed

modified:__tests__/produce.ts+7 added
733 unmodified lines
734 })735 assert(res, _ as State | undefined)736 }737 {738 // as any739 const res = produce(base as State, draft => {740 return nothing as any741 })742 assert(res, _ as State)743 }744 {745 // nothing not allowed746 // @ts-expect-error747 produce(base as State, draft => {748 return nothing
23 unmodified lines
modified:src/types/types-external.ts+7 added-7 removed
209 unmodified lines
210 recipe: Recipe,211 initialState: State212 ): InferCurriedFromInitialStateAndRecipe<State, Recipe, false>213214 /** Promisified dormal producer */215 <Base, D = Draft<Base>>(216 base: Base,217 recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,218 listener?: PatchListener219 ): Promise<Base>220214 /** Normal producer */215 <Base, D = Draft<Base>>( // By using a default inferred D, rather than Draft<Base> in the recipe, we can override it.216 base: Base,217 recipe: (draft: D) => ValidRecipeReturnType<D>,218 listener?: PatchListener219 ): Base220221 /** Promisified dormal producer */222 <Base, D = Draft<Base>>(223 base: Base,224 recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,225 listener?: PatchListener226 ): Promise<Base>227}228229/**230 * Like `produce`, but instead of just returning the new state,
26 unmodified lines