@@ -17,6 +17,8 @@ type MODES = {
1717 MULTI_PROCESS : number ;
1818} ;
1919
20+ type Callback < T > = ( error : Error | null , result : T | null ) => void ;
21+
2022declare module MMKVStorage {
2123 export const MODES : MODES ;
2224
@@ -25,10 +27,8 @@ declare module MMKVStorage {
2527 const myVar : string ;
2628
2729 class API {
28-
29-
30- /**
31- * Set a string value to storage for a given key.
30+ /**
31+ * Set a string value to storage for a given key.
3232 * This method is added for redux-persist support. It is similar to setStringAsync()
3333 *
3434 * @param {String } key
@@ -43,7 +43,6 @@ declare module MMKVStorage {
4343 */
4444 getItem ( key : string ) : Promise < string > ;
4545
46-
4746 /**
4847 * Set a string value to storag for a given key.
4948 *
@@ -101,7 +100,7 @@ declare module MMKVStorage {
101100 * Get an Object from storage for a given key.
102101 * @param {String } key
103102 */
104- getMapAsync ( key : string ) : Promise < object | null > ;
103+ getMapAsync < T extends object > ( key : string ) : Promise < T | null > ;
105104 /**
106105 * Set an array to the db.
107106 * @param {String } key
@@ -113,7 +112,7 @@ declare module MMKVStorage {
113112 * @param {String } key
114113 */
115114
116- getArrayAsync ( key : string ) : Promise < Array < any > | null > ;
115+ getArrayAsync < T extends any > ( key : string ) : Promise < Array < T > | null > ;
117116 /**
118117 * Retrieve multiple Objects for a given array of keys. Currently will work only if data for all keys is an Object.
119118 * Arrays will also be returned but wrappen in a object.
@@ -122,7 +121,9 @@ declare module MMKVStorage {
122121 *
123122 * @param {Array } keys
124123 */
125- getMultipleItemsAsync ( keys : Array < string > ) : Promise < Array < object > > ;
124+ getMultipleItemsAsync < T extends object > (
125+ keys : Array < string >
126+ ) : Promise < Array < T > > ;
126127
127128 clearStore ( ) : Promise < boolean > ;
128129 /**
@@ -139,87 +140,96 @@ declare module MMKVStorage {
139140 *
140141 * @param {String } key
141142 * @param {String } value
142- * @param {Function } callback
143+ * @param {Callback<boolean> } callback
143144 */
144- setString ( key : string , value : string , callback ?: Function ) : null ;
145+ setString ( key : string , value : string , callback ?: Callback < boolean > ) : null ;
145146 /**
146147 * Get a string value for a given key.
147148 * @param {String } key
148- * @param {Function } callback
149+ * @param {Callback<string> } callback
149150 */
150- getString ( key : string , callback ?: Function ) : string | null ;
151+ getString ( key : string , callback ?: Callback < string > ) : string | null ;
151152
152153 /**
153154 * Set a number value to storage for a given key.
154155 *
155156 * @param {String } key
156157 * @param {number } value
157- * @param {Function } callback
158+ * @param {Callback<boolean> } callback
158159 */
159- setInt ( key : string , value : number , callback ?: Function ) : null ;
160+ setInt ( key : string , value : number , callback ?: Callback < boolean > ) : null ;
160161
161162 /**
162163 * Get a number value for a given key
163164 * @param {String } key
164- * @param {Function } callback
165+ * @param {Callback<number> } callback
165166 */
166- getInt ( key : string , callback ?: Function ) : number | null ;
167+ getInt ( key : string , callback ?: Callback < number > ) : number | null ;
167168
168169 /**
169170 * Set a boolean value to storag for a given key.
170171 *
171172 * @param {String } key
172173 * @param {boolean } value
173- * @param {Function } callback
174+ * @param {Callback<boolean> } callback
174175 */
175- setBool ( key : string , value : boolean , callback ?: Function ) : null ;
176+ setBool ( key : string , value : boolean , callback ?: Callback < boolean > ) : null ;
176177
177178 /**
178179 * Get a boolean value for a given key.
179180 * @param {String } key
180- * @param {Function } callback
181+ * @param {Callback<boolean> } callback
181182 */
182- getBool ( key : string , callback ?: Function ) : boolean | null ;
183+ getBool ( key : string , callback ?: Callback < boolean > ) : boolean | null ;
183184
184185 /**
185186 * Set an Object to storage for a given key.
186187 *
187188 * @param {String } key
188189 * @param {Object } value
189- * @param {Function } callback
190+ * @param {Callback<boolean> } callback
190191 */
191192
192- setMap ( key : string , value : object , callback ?: Function ) : null ;
193+ setMap ( key : string , value : object , callback ?: Callback < boolean > ) : null ;
193194 /**
194195 * Get an Object from storage for a given key.
195196 * @param {String } key
196- * @param {Function } callback
197+ * @param {Callback<object> } callback
197198 */
198- getMap ( key : string , callback ?: Function ) : object | null ;
199+ getMap < T extends object > ( key : string , callback ?: Callback < T > ) : T | null ;
199200 /**
200201 * Set an array to the db.
201202 * @param {String } key
202203 * @param {Array } array
203- * @param {Function } callback
204+ * @param {Callback<boolean> } callback
204205 */
205- setArray ( key : string , value : Array < any > , callback ?: Function ) : null ;
206+ setArray (
207+ key : string ,
208+ value : Array < any > ,
209+ callback ?: Callback < boolean >
210+ ) : null ;
206211 /**
207212 * get an array from the storage for give key.
208213 * @param {String } key
209- * @param {Function } callback
214+ * @param {Array<any> } callback
210215 */
211-
212- getArray ( key : string , callback ?: Function ) : Array < any > | null ;
216+ getArray < T extends any > (
217+ key : string ,
218+ callback ?: Callback < Array < T > >
219+ ) : Array < T > | null ;
213220 /**
214221 * Retrieve multiple Objects for a given array of keys. Currently will work only if data for all keys is an Object.
215222 * Arrays will also be returned but wrappen in a object.
216223 *
217224 * **Will not work if a key as a String value.**
218225 *
219226 * @param {Array } keys
220- * @param {Function } callback
227+ * @param {Array<object> } callback
221228 */
222- getMultipleItems ( keys : Array < string > , callback ?: Function ) : Array < object > ;
229+ getMultipleItems < T extends object > (
230+ keys : Array < string > ,
231+ callback ?: Callback < Array < T > >
232+ ) : Array < T > ;
223233
224234 /**
225235 *
@@ -378,7 +388,7 @@ declare module MMKVStorage {
378388 key : string ,
379389 secureKeyStorage : boolean ,
380390 alias : string ,
381- accessibleMode :ACCESSIBLE
391+ accessibleMode : ACCESSIBLE
382392 ) : Promise < boolean > ;
383393
384394 /**
@@ -400,7 +410,7 @@ declare module MMKVStorage {
400410 key : string ,
401411 secureKeyStorage : boolean ,
402412 alias : string ,
403- accessibleMode :ACCESSIBLE
413+ accessibleMode : ACCESSIBLE
404414 ) : Promise < boolean > ;
405415 }
406416
@@ -429,14 +439,14 @@ declare module MMKVStorage {
429439 setAccessibleIOS ( accessible : ACCESSIBLE ) : this;
430440
431441 /**
432- * Provide a custom key to encrypt the storage. Use this if you dont want to generate the key automatically.
433- * You must call withEncryption() to use this.
434- * To store your key for later use call withSecureKeyStorage() too.
435- *
436- * @param {string } key the key to encrypt the storage with
437- * @param {boolean } secureKeyStorage Should the key be stored securely.
438- * @param {string } alias Provide an alias for key storage. Default alias is aliasPrefix + instanceID
439- */
442+ * Provide a custom key to encrypt the storage. Use this if you dont want to generate the key automatically.
443+ * You must call withEncryption() to use this.
444+ * To store your key for later use call withSecureKeyStorage() too.
445+ *
446+ * @param {string } key the key to encrypt the storage with
447+ * @param {boolean } secureKeyStorage Should the key be stored securely.
448+ * @param {string } alias Provide an alias for key storage. Default alias is aliasPrefix + instanceID
449+ */
440450
441451 encryptWithCustomKey (
442452 key : string ,
0 commit comments