I'm trying to use axios-extensions and localforage to create an axios cache adapter that uses the localforage library for its storage (our codebase is dated and I'm looking to replace the old axios-cache-adapter, which is not updated for the newest axios version). I'll abstract away some of the details here to make the situation simpler:
localforage has a get method with a signature like this:
get(key: string): Promise<string | undefined>
However, the axios-extensions cache adapter function expects a method with a signature like this:
get(key: string): Promise<string> | undefined
It feels like it should be simple to write a wrapper for localforage's get, but I haven't found a way to do it yet without something ridiculous like busy-waiting. Is there any way to wrap the localforage get function in order to synchronously return undefined, even though I can't know if a field exists until the promise resolves? Do I really need to use a different library/create a patch for this one in order to do this?