From 686013aba679abfa1ccd03619dbd1b673c015a60 Mon Sep 17 00:00:00 2001 From: Nicolas Charpentier Date: Wed, 29 May 2024 11:43:14 -0400 Subject: [PATCH] feat(types): turn `LocalForageWrapper` into a generic class --- src/storageWrappers/LocalForageWrapper.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/storageWrappers/LocalForageWrapper.ts b/src/storageWrappers/LocalForageWrapper.ts index eed23105..b2f03993 100644 --- a/src/storageWrappers/LocalForageWrapper.ts +++ b/src/storageWrappers/LocalForageWrapper.ts @@ -1,14 +1,15 @@ import { PersistentStorage } from '../types'; -export class LocalForageWrapper - implements PersistentStorage { +export class LocalForageWrapper + implements PersistentStorage +{ protected storage; - constructor(storage: LocalForageInterface) { + constructor(storage: LocalForageInterface) { this.storage = storage; } - getItem(key: string): Promise { + getItem(key: string): Promise { return this.storage.getItem(key); } @@ -16,7 +17,7 @@ export class LocalForageWrapper return this.storage.removeItem(key); } - setItem(key: string, value: string | object | null): Promise { + setItem(key: string, value: T | null): Promise { return new Promise((resolve, reject) => { this.storage .setItem(key, value) @@ -26,12 +27,9 @@ export class LocalForageWrapper } } -interface LocalForageInterface { +export interface LocalForageInterface { // Actual type definition: https://github.com/localForage/localForage/blob/master/typings/localforage.d.ts#L17 - getItem(key: string): Promise; - setItem( - key: string, - value: string | object | null, - ): Promise; + getItem(key: string): Promise; + setItem(key: string, value: T | null): Promise; removeItem(key: string): Promise; }