Skip to content

Commit

Permalink
fix(type): fix curried create return type (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib authored Sep 17, 2024
1 parent df531a5 commit a38f0dc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/makeCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type MakeCreator = <
<T extends any, O extends PatchesOptions = _O, F extends boolean = _F>(
base: T,
options?: ExternalOptions<O, F>
): [T, () => Result<T, O, F>];
): [Draft<T>, () => Result<T, O, F>];
};

/**
Expand Down
10 changes: 0 additions & 10 deletions test/apply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' } });
});

0 comments on commit a38f0dc

Please sign in to comment.