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

Expand isAxiosError types #4344

Merged
merged 9 commits into from May 12, 2022
Merged

Expand isAxiosError types #4344

merged 9 commits into from May 12, 2022

Conversation

Argeento
Copy link
Contributor

isAxiosError returns AxiosError<any>

This change allows to pass type for AxiosError

// Old behavior #1
if (axios.isAxiosError(error)) {
   error.response?.data.message // any
}
// Old behavior #2
if (axios.isAxiosError(error)) {
   (error as AxiosError<MyErrorInterface>).response?.data.message // string | undefined
}

// Behavior after this change #1 (Non-breaking change)
if (axios.isAxiosError(error)) {
   error.response?.data.message // any
}
// Behavior after this change #2 (Desired behavior)
if (axios.isAxiosError<MyErrorInterface>(error)) {
   error.response?.data.message // string | undefined
}

index.d.ts Outdated Show resolved Hide resolved
@latipun7
Copy link

This PR is duplicate of long ongoing PR #3816 (I can drop the formatting commit if the maintainer didn't want it)

@jasonsaayman
Copy link
Member

Closing as the types have already been fixed

@merlindru
Copy link

@jasonsaayman isAxiosError still doesn't take generics 😕

I got here by #3815

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants