From a38f0dc5f12d273553a3e522dc25319279151f02 Mon Sep 17 00:00:00 2001 From: Michael Lin Date: Tue, 17 Sep 2024 17:14:59 +0800 Subject: [PATCH] fix(type): fix curried create return type (#58) --- src/makeCreator.ts | 2 +- test/apply.test.ts | 10 ---------- test/index.test.ts | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/makeCreator.ts b/src/makeCreator.ts index 8598837e..e4e93881 100644 --- a/src/makeCreator.ts +++ b/src/makeCreator.ts @@ -57,7 +57,7 @@ type MakeCreator = < ( base: T, options?: ExternalOptions - ): [T, () => Result]; + ): [Draft, () => Result]; }; /** diff --git a/test/apply.test.ts b/test/apply.test.ts index b5207517..f2473ff8 100644 --- a/test/apply.test.ts +++ b/test/apply.test.ts @@ -1305,16 +1305,6 @@ test('merge multiple patches', () => { enablePatches: true, } ); - console.log( - JSON.stringify( - { - patches, - inversePatches, - }, - null, - 2 - ) - ); const [state1, patches1, inversePatches1] = create( state, (draft) => { diff --git a/test/index.test.ts b/test/index.test.ts index 3b457829..23f42bc0 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -3977,3 +3977,18 @@ it('#51-2 nested drafts work after current', () => { k2: { abc: 100, def: 200 }, }); }); + +test('#57 - curried create returns object of wrong type', () => { + const state: { + readonly a: { + readonly x: string; + }; + } = { a: { x: 'x' } }; + + const [draft, finalize] = create(state); + + draft.a.x = 'test'; + + const nextState = finalize(); + expect(nextState).toEqual({ a: { x: 'test' } }); +});