[Types] Type MMKVManager

This commit is contained in:
redstonekasi 2023-01-17 00:52:20 +01:00 committed by Beef
parent 3c95bb1024
commit 71f687e345
2 changed files with 38 additions and 4 deletions

View file

@ -1,9 +1,9 @@
import { Indexable } from "@types";
import { Indexable, MMKVManager } from "@types";
import { ReactNative as RN } from "@metro/hoist";
// Discord's custom special storage sauce
// TODO: Type this
const MMKVManager = RN.NativeModules.MMKVManager;
const MMKVManager = RN.NativeModules.MMKVManager as MMKVManager;
// TODO: React hook?
// TODO: Clean up types, if necessary
@ -34,7 +34,7 @@ export default function createStorage<T>(storeName: string, onRestore?: (parsed:
}
}
MMKVManager.getItem(storeName).then(async function (v: any) {
MMKVManager.getItem(storeName).then(async function (v) {
if (!v) return;
const parsed: T & Indexable<any> = JSON.parse(v);
@ -46,4 +46,4 @@ export default function createStorage<T>(storeName: string, onRestore?: (parsed:
})
return new Proxy(internalStore, proxyValidator) as T;
}
}