-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
issue246.ts
50 lines (42 loc) · 1022 Bytes
/
issue246.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Action, action, createStore } from 'easy-peasy';
interface Item {
id: number;
name: string;
}
interface BeholderModel extends BaseListModel<BeholderModel> {
// Extra stuff for interface
beholderName: string;
}
interface CreatorModel extends BaseListModel<CreatorModel> {
// Extra stuff for interface
creatorName: string;
}
// error at <T, ...> in setList
interface BaseListModel<T extends object> {
list: Item[];
setList: Action<T, Item[]>;
}
interface StoreModel {
beholder: BeholderModel;
creator: CreatorModel;
}
const model: StoreModel = {
beholder: {
beholderName: 'foo',
list: [],
setList: action((state, payload) => {
state.list = payload;
}),
},
creator: {
creatorName: 'foo',
list: [],
setList: action((state, payload) => {
state.list = payload;
}),
},
};
const store = createStore(model);
store.getState().beholder.beholderName;
store.getState().beholder.list;
store.getActions().creator.setList([{ id: 1, name: 'foo' }]);