@@ -187,6 +187,9 @@ describe("curried producer", () => {
187187 let foo = produce ( ( s : State , a : number , b : number ) => { } )
188188 assert ( foo , _ as Recipe )
189189 foo ( _ as State , 1 , 2 )
190+
191+ // @ts -expect-error
192+ foo ( undefined , 1 , 2 )
190193 }
191194
192195 // Using argument parameters:
@@ -745,6 +748,13 @@ it("infers curried", () => {
745748 const n = f ( base as ROState )
746749 assert ( n , _ as ROState ) // yay!
747750 }
751+ {
752+ // explicitly use generic, but curried
753+ const f = produce < ROState > ( draft => {
754+ draft . count ++
755+ } )
756+ assert ( f , _ as ( state : ROState ) => ROState )
757+ }
748758}
749759
750760it ( "allows for mixed property value types" , ( ) => {
@@ -760,3 +770,22 @@ it("allows for mixed property value types", () => {
760770 }
761771 } )
762772} )
773+
774+ it ( "#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+ )
786+
787+ 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 state
790+ expect ( ( ) => reducerNoInitial ( undefined , { type : "inc" } ) ) . toThrow ( )
791+ } )
0 commit comments