refactor(core): harden API parsing and improve type safety

This commit is contained in:
LTbinglingfeng
2026-02-08 09:42:00 +08:00
parent 3783bec983
commit 6c2cd761ba
39 changed files with 689 additions and 404 deletions

View File

@@ -13,7 +13,7 @@ interface UseApiOptions<T> {
successMessage?: string;
}
export function useApi<T = any, Args extends any[] = any[]>(
export function useApi<T = unknown, Args extends unknown[] = unknown[]>(
apiFunction: (...args: Args) => Promise<T>,
options: UseApiOptions<T> = {}
) {
@@ -38,8 +38,9 @@ export function useApi<T = any, Args extends any[] = any[]>(
options.onSuccess?.(result);
return result;
} catch (err) {
const errorObj = err as Error;
} catch (err: unknown) {
const errorObj =
err instanceof Error ? err : new Error(typeof err === 'string' ? err : 'Unknown error');
setError(errorObj);
if (options.showErrorNotification !== false) {