refactor: improve generic typing for unlock and overhaul example app UI styling

This commit is contained in:
Vitalii Litvinchuk
2026-06-11 20:14:31 +03:00
parent 62d39b7255
commit eecda919e6
3 changed files with 290 additions and 191 deletions
+5 -6
View File
@@ -24,11 +24,10 @@ export function useCryptoLocker<T = unknown>(dependencies: Record<string, any> =
* @param password The AES password.
*/
const unlock = useCallback(
async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetchData: () => Promise<any>,
async <M, R = M extends { default: infer D } ? D : M>(
fetchData: () => Promise<M>,
password: string
): Promise<T> => {
): Promise<R> => {
setStatus("loading");
setError(null);
@@ -75,9 +74,9 @@ export function useCryptoLocker<T = unknown>(dependencies: Record<string, any> =
);
fn(requireFn, exportsObj, moduleObj, React);
const parsed = (moduleObj.exports.default ?? moduleObj.exports) as T;
const parsed = (moduleObj.exports.default ?? moduleObj.exports) as R;
setDecryptedData(() => parsed);
setDecryptedData(() => parsed as unknown as T);
setStatus("success");
return parsed;
} catch (err: unknown) {