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

@Argeento Argeento commented Dec 21, 2021

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

latipun7 commented Dec 30, 2021

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

jasonsaayman commented May 4, 2022

Closing as the types have already been fixed

@merlindru
Copy link

merlindru commented May 4, 2022

@jasonsaayman isAxiosError still doesn't take generics 😕

I got here by #3815

@jasonsaayman jasonsaayman reopened this May 4, 2022
@jasonsaayman jasonsaayman added component:typescript follow-up Issue or pull request requires a follow. labels May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
follow-up Issue or pull request requires a follow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants