diff --git a/src/hooks/useFullscreenLoading.ts b/src/hooks/useFullscreenLoading.ts index 155c481..9d7d2e4 100644 --- a/src/hooks/useFullscreenLoading.ts +++ b/src/hooks/useFullscreenLoading.ts @@ -9,6 +9,12 @@ interface ILoadingInstance { close: () => void } +interface IUseFullscreenLoading { + ReturnType>(fn: T, options?: LoadingOptions): ( + ...args: Parameters + ) => Promise> | ReturnType +} + /** * 传入一个函数 fn,在它执行周期内,加上「全屏」loading, * 如果: @@ -19,10 +25,7 @@ interface ILoadingInstance { * @param options LoadingOptions * @returns Function 一个新的函数,去执行它吧 */ -export function useFullscreenLoading( - fn: (...args: any[]) => T | Promise, - options: LoadingOptions = {} -): (...args: any[]) => Promise { +export const useFullscreenLoading: IUseFullscreenLoading = (fn, options = {}) => { let loadingInstance: ILoadingInstance const showLoading = (options: LoadingOptions) => { loadingInstance = ElLoading.service(options) @@ -31,7 +34,7 @@ export function useFullscreenLoading( loadingInstance && loadingInstance.close() } const _options = { ...defaultOptions, ...options } - return (...args: any[]) => { + return (...args) => { try { showLoading(_options) const result = fn(...args)