From 104cecfba8c976ca52e47d2da3a158c604ff4c06 Mon Sep 17 00:00:00 2001 From: unadlib Date: Thu, 2 Jan 2025 00:38:26 +0800 Subject: [PATCH] test(type): add type example --- packages/core/test/index.test.ts | 42 ++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/core/test/index.test.ts b/packages/core/test/index.test.ts index 629660e..b8e9769 100644 --- a/packages/core/test/index.test.ts +++ b/packages/core/test/index.test.ts @@ -420,9 +420,47 @@ describe('Slices', () => { } }); - const useServerStore = create( + const counter1: Slices< { - counter + counter1: { + count: number; + increment: () => void; + }; + }, + 'counter1' + > = (set) => ({ + count: 0, + increment() { + set((draft) => { + draft.counter1.count += 1; + }); + } + }); + + // TODO: improve type for slices + const useServerStore = create<{ + counter: Slices< + { + counter: { + count: number; + increment: () => void; + }; + }, + 'counter' + >; + counter1: Slices< + { + counter1: { + count: number; + increment: () => void; + }; + }, + 'counter1' + >; + }>( + { + counter, + counter1 }, { name: 'test',