Skip to content

Commit

Permalink
improve the types
Browse files Browse the repository at this point in the history
  • Loading branch information
huang2002 committed Jan 30, 2019
1 parent 6db3e32 commit 4ac55bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/HUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const HUI = <P extends object = _EleProps, S extends _Store = _Store, C e
): _HNode<P, S, C> => ({
isHN: true,
type,
desc: registry.get(type as any),
desc: registry.get(type as _HType),
props: _assign({ children: children.flat(_Infinity) }, props) as unknown as _HProps<P>,
active: true
});
Expand Down
12 changes: 6 additions & 6 deletions src/core/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface Store<T extends object = any, H extends HandlerMap<T> = any> {

push<K extends keyof T>(key: K, ...items: AssertArray<T[K]>): this;
unshift<K extends keyof T>(key: K, ...items: AssertArray<T[K]>): this;
slice(key: keyof T, start: number, end: number): this;
slice(key: keyof T, start: number, end?: number): this;
splice<K extends keyof T>(key: K, start: number, deleteCount?: number): this;
splice<K extends keyof T>(key: K, start: number, deleteCount: number, ...items: AssertArray<T[K]>): this;

Expand Down Expand Up @@ -143,29 +143,29 @@ export const createStore = function crtSto<
},

toggle: function s_toggle(key) {
return store.set(key, !store.get(key) as any);
return store.set(key, !store.get(key) as unknown as T[keyof T]);
},

inc: function s_inc(key, addition = 1) {
return store.set(key, store.get(key) + addition);
},

push: function s_push(key, ...items) {
return store.set(key, (store.get(key) as unknown as any[]).concat(items) as any);
return store.set(key, (store.get(key) as unknown as any[]).concat(items) as unknown as T[keyof T]);
},

unshift: function s_unshift(key, ...items) {
return store.set(key, items.concat(store.get(key)) as any);
return store.set(key, items.concat(store.get(key)) as unknown as T[keyof T]);
},

slice: function s_slice(key, start, end) {
return store.set(key, (store.get(key) as unknown as any[]).slice(start, end) as any);
return store.set(key, (store.get(key) as unknown as any[]).slice(start, end) as unknown as T[keyof T]);
},

splice: function s_splice(key: keyof T, start: number, deleteCount: number, ...items: any[]) {
const arr = (store.get(key) as unknown as any[]).slice();
_splice.apply(arr, [start, deleteCount].concat(items) as SpliceArgs);
return store.set(key, arr as any);
return store.set(key, arr as unknown as T[keyof T]);
},

handle: function s_handle(name, handler) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const define = function <P extends object = any, S extends Store = Store,

const type = _Symbol(name) as unknown as HType<P, S, C>;

registry.set(type as any, desc as any);
registry.set(type as HType, desc as HDesc);

return type;

Expand Down

0 comments on commit 4ac55bf

Please sign in to comment.