-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
45 lines (44 loc) · 1.26 KB
/
index.d.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
declare type CookieSetParam<T = undefined> = {
key:string;
value:T extends undefined ? string | object : Partial<T>;
domain:string;
maxAge:string;
};
export declare class CookieStorage {
set(spec:CookieSetParam):void;
get<T>(key:string):T;
update<T>(spec:CookieSetParam<T>):void;
delete(key:string):void;
}
export declare class LocalStorage {
set(key:string, value:string | object):void;
get<T>(key:string):T;
update<T>(key:string, value:Partial<T>):void;
delete(key:string):void;
}
export declare class SessionStorage {
set(key:string, value:string | {
[key:string]:any;
}):void;
get<T>(key:string):T;
update<T>(key:string, value:Partial<T>):void;
delete(key:string):void;
}
export declare class IndexDB {
set(key:string, value:string):void;
get(key:string):string;
delete(key:string):void;
}
declare type StoresType = {
'localStorage':LocalStorage;
'sessionStorage':SessionStorage;
'cookieStorage':CookieStorage;
'indexDB':IndexDB;
};
declare type StoreKey = keyof StoresType;
declare type createType<T> = {
type?:T;
namespace?:string;
};
export default function createStore():LocalStorage;
export default function createStore<T extends createType<StoreKey>>(spec:T):T['type'] extends StoreKey ? StoresType[T['type']] : LocalStorage;