Skip to content
Myr

fix: remove invalid curried producer type (#1216)

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

authored by Dean Kerr · committed by GitHub · parent 4f1a96f · Browse files · 2 files+29 added−6 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+29 added−6 removed

  • tests:+29 added−0 removed
  • other:+0 added−6 removed

2 files+29 added−6 removed

modified:__tests__/produce.ts+29 added
185 unmodified lines
186 type Recipe = (state: State, a: number, b: number) => State187 let foo = produce((s: State, a: number, b: number) => {})188 assert(foo, _ as Recipe)189 foo(_ as State, 1, 2)190191 // @ts-expect-error192 foo(undefined, 1, 2)193 }194195 // Using argument parameters:196 {
550 unmodified lines
747 })748 const n = f(base as ROState)749 assert(n, _ as ROState) // yay!750 }751 {752 // explicitly use generic, but curried753 const f = produce<ROState>(draft => {754 draft.count++755 })756 assert(f, _ as (state: ROState) => ROState)757 }758}759760it("allows for mixed property value types", () => {761 type TestReadonlyObject = {
7 unmodified lines
769 draft.testObjectOrNull.testProperty = 5770 }771 })772})773774it("#877 - produce with typed state generic requires initial state", () => {775 const reducerNoInitial = produce<{count: number}, [{type: "inc"}]>(776 (draft, action: {type: "inc"}) => {777 if (action.type === "inc") draft.count++778 }779 )780 const reducer = produce<{count: number}, [{type: "inc"}]>(781 (draft, action: {type: "inc"}) => {782 if (action.type === "inc") draft.count++783 },784 {count: 0}785 )786787 expect(reducer({count: 0}, {type: "inc"})).toEqual({count: 1})788 expect(reducer(undefined, {type: "inc"})).toEqual({count: 1})789 // @ts-expect-error runtime error without initial state790 expect(() => reducerNoInitial(undefined, {type: "inc"})).toThrow()791})
modified:src/types/types-external.ts-6 removed
182 unmodified lines
183 recipe: Recipe184 ): InferCurriedFromRecipe<Recipe, false>185186 /** Curried producer that infers curried from the State generic, which is explicitly passed in. */187 <State>(188 recipe: (189 state: Draft<State>,190 initialState: State191 ) => ValidRecipeReturnType<State>192 ): (state?: State) => State187 <State, Args extends any[]>(188 recipe: (189 state: Draft<State>,190 ...args: Args
52 unmodified lines