import { PersistentStorage } from '../types'; export class LocalForageWrapper implements PersistentStorage { protected storage; constructor(storage: LocalForageInterface) { this.storage = storage; } getItem(key: string): Promise { return this.storage.getItem(key); } removeItem(key: string): Promise { return this.storage.removeItem(key); } setItem(key: string, value: string | object | null): Promise { return new Promise((resolve, reject) => { this.storage .setItem(key, value) .then(() => resolve()) .catch(() => reject()); }); } } 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; removeItem(key: string): Promise; }