Skip to content

Commit 8da6218

Browse files
committed
Fix type error
1 parent 784731f commit 8da6218

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

src/drivers/sessionStorage.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,17 @@ function removeItem(key, callback) {
214214
return promise;
215215
}
216216

217-
// Set a key's value and run an optional callback once the value is set.
218-
// Unlike Gaia's implementation, the callback function is passed the value,
219-
// in case you want to operate on that value only after you're sure it
220-
// saved, or something like that.
217+
/**
218+
* Set a key's value and run an optional callback once the value is set.
219+
* Unlike Gaia's implementation, the callback function is passed the value,
220+
* in case you want to operate on that value only after you're sure it
221+
* saved, or something like that.
222+
* @template T
223+
* @param {string} key - The key under which the value is stored.
224+
* @param {T} value - The value to be stored, can be of any type.
225+
* @param {(err: any, value: T) => void} [callback] - Optional callback function to be called after the value is set.
226+
* @returns {Promise<T>}
227+
*/
221228
async function setItem(key, value, callback) {
222229
key = normalizeKey(key);
223230
await this.ready();
@@ -245,6 +252,8 @@ async function setItem(key, value, callback) {
245252
}
246253
}
247254
});
255+
256+
return value;
248257
}
249258

250259
function dropInstance(options, callback) {
@@ -286,15 +295,15 @@ const sessionStorageWrapper = {
286295
_driver: 'sessionStorageWrapper',
287296
_initStorage: _initStorage,
288297
_support: isSessionStorageValid(),
289-
iterate: iterate,
290-
getItem: getItem,
291-
setItem: setItem,
292-
removeItem: removeItem,
293-
clear: clear,
294-
length: length,
295-
key: key,
296-
keys: keys,
297-
dropInstance: dropInstance,
298+
iterate,
299+
getItem,
300+
setItem,
301+
removeItem,
302+
clear,
303+
length,
304+
key,
305+
keys,
306+
dropInstance,
298307
};
299308

300309
export default sessionStorageWrapper;

src/types/drivers/sessionStorage.d.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ declare namespace sessionStorageWrapper {
1616
declare function _initStorage(options: any): void;
1717
declare function iterate(iterator: any, callback: any): any;
1818
declare function getItem(key: any, callback: any): any;
19-
declare function setItem(key: any, value: any, callback: any): Promise<void>;
19+
/**
20+
* Set a key's value and run an optional callback once the value is set.
21+
* Unlike Gaia's implementation, the callback function is passed the value,
22+
* in case you want to operate on that value only after you're sure it
23+
* saved, or something like that.
24+
* @template T
25+
* @param {string} key - The key under which the value is stored.
26+
* @param {T} value - The value to be stored, can be of any type.
27+
* @param {(err: any, value: T) => void} [callback] - Optional callback function to be called after the value is set.
28+
* @returns {Promise<T>}
29+
*/
30+
declare function setItem<T>(key: string, value: T, callback?: (err: any, value: T) => void): Promise<T>;
2031
declare function removeItem(key: any, callback: any): any;
2132
declare function clear(callback: any): any;
2233
declare function length(callback: any): any;

src/types/drivers/sessionStorage.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/types/storage.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ declare class Storage {
2828
getItemName(id: any): string;
2929
}
3030
declare namespace Storage {
31-
export let sessionStorageInitialized: any;
31+
export let sessionStorageInitialized: Promise<void>;
3232
export { localForage };
3333
}
34+
import localForage from 'localforage';
3435
//# sourceMappingURL=storage.d.ts.map

src/types/storage.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)