Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useAxios)!: error should return type unknown #2807

Merged
merged 5 commits into from
Mar 4, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/integrations/useAxios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface UseAxiosReturn<T, R = AxiosResponse<T>, D = any> {
/**
* Any errors that may have occurred
*/
error: ShallowRef<AxiosError<T, D> | undefined>
error: ShallowRef<unknown | undefined>

/**
* Aborts the current request
Expand Down Expand Up @@ -92,6 +92,7 @@ export interface UseAxiosOptions<T = any> {
*
*/
immediate?: boolean

/**
* Use shallowRef.
*
Expand Down Expand Up @@ -128,7 +129,10 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
const argsPlaceholder = isString(url) ? 1 : 0
let defaultConfig: RawAxiosRequestConfig<D> = {}
let instance: AxiosInstance = axios
let options: UseAxiosOptions<T> = { immediate: !!argsPlaceholder, shallow: true }
let options: UseAxiosOptions<T> = {
immediate: !!argsPlaceholder,
shallow: true,
}

const isAxiosInstance = (val: any) => !!val?.request

Expand Down Expand Up @@ -159,7 +163,7 @@ export function useAxios<T = any, R = AxiosResponse<T>, D = any>(...args: any[])
const isFinished = ref(false)
const isLoading = ref(false)
const isAborted = ref(false)
const error = shallowRef<AxiosError<T>>()
const error = shallowRef<unknown>()

const cancelTokenSource = axios.CancelToken.source
let cancelToken: CancelTokenSource = cancelTokenSource()
Expand Down