Skip to content

Commit fcbe380

Browse files
committed
Fix type issues of useStore test suite
1 parent f755763 commit fcbe380

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

tests/useStore.test.tsx

+27-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ describe('useStore', () => {
6565
});
6666

6767
it('should allow to update the value', () => {
68-
const {useStore} = createStore();
68+
type Store = {
69+
items: number[];
70+
}
71+
const {useStore} = createStore<Store>();
6972

7073
function Test() {
7174
const [items, setItems] = useStore.items([]);
@@ -88,8 +91,18 @@ describe('useStore', () => {
8891
});
8992

9093
it('should be possible to create more than one store', () => {
91-
const {useStore: useCart, getStore: getCart} = createStore({items: []});
92-
const {useStore: useCounter} = createStore({count: 0});
94+
type CartStore = {
95+
items: string[];
96+
}
97+
98+
type CounterStore = {
99+
count: number;
100+
}
101+
102+
const {useStore: useCart, getStore: getCart} = createStore<CartStore>({
103+
items: []
104+
});
105+
const {useStore: useCounter} = createStore<CounterStore>({count: 0});
93106

94107
function Test() {
95108
const [count] = useCounter.count();
@@ -120,14 +133,23 @@ describe('useStore', () => {
120133

121134
it('should work changing the index of an array on fly', () => {
122135
const onAfterUpdate = jest.fn();
123-
const {useStore} = createStore({
136+
type Items = {
137+
price: number;
138+
name: string;
139+
}
140+
type Store = {
141+
cart: {
142+
items: Items[];
143+
}
144+
}
145+
const {useStore} = createStore<Store>({
124146
cart: {
125147
items: [],
126148
},
127149
}, onAfterUpdate);
128150

129151
function Test() {
130-
const [state, setState] = useState(0);
152+
const [state, setState] = useState<number>(0);
131153
const [item, setItem] = useStore.cart.items[state]();
132154

133155
return (

0 commit comments

Comments
 (0)