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

Exposing the Axios constructor in index.d.ts #2872

Merged
merged 2 commits into from Sep 5, 2021

Conversation

TimWolla
Copy link
Contributor

@TimWolla TimWolla commented Apr 2, 2020

This patch allows TypeScript users to extend the Axios class without
the type checker complaining.

see 7548f2f


Fixes #3017

@TimWolla
Copy link
Contributor Author

TimWolla commented May 7, 2020

Could you please take a look? After I used the “Update branch” button on April, 8th Travis is green instead of a stuck yellow as well.

@donaldpipowitch
Copy link

@chinesedfan Is there something which still needs to be done for this MR?

@ArrayKnight
Copy link

ArrayKnight commented Jun 26, 2020

Would it be possible to get this merged soon, please?

@jasonsaayman jasonsaayman self-assigned this Jun 26, 2020
@jasonsaayman
Copy link
Member

Will look at this as soon as I can

@TimWolla
Copy link
Contributor Author

@remcohaszing Can you return the favor and review this one, please? The reason behind this change is being able to class Foo extends Axios with import { default as axios, Axios } from 'axios';.

It should be non-breaking, but a second pair of eyes would be helpful.

@remcohaszing
Copy link
Contributor

I looked into it. This allow to use the following statements that were previously not possible:

import axios from 'Axios';

const foo = new axios.Axios();  // Use Axios constructor
foo instanceof axios.Axios;  // Instanceof check for Axios instance
foo('/');  // This is unsupported, and now also an error in TypeScript

The instanceof check doesn’t work for instances created axios.create(), but the call expression does work in that case.

All of these cases are properly handled by the new type definitions, and it’s non-breaking. LGTM 😃

@TimWolla
Copy link
Contributor Author

@jasonsaayman I'd appreciate if you could take a look at this one. I'm happy to answer all your questions about it, like we did in #2797 👍

@TimWolla
Copy link
Contributor Author

@jasonsaayman Friendly ping. I just rebased this PR once again and it's already been reviewed by Remco.

This patch allows TypeScript users to extend the `Axios` class without
the type checker complaining.

see 7548f2f
@TimWolla TimWolla force-pushed the typescript-axios-constructor branch from 61db8ad to c72c87a Compare August 13, 2021 13:19
@TimWolla
Copy link
Contributor Author

@jasonsaayman Any chance? I just rebased the PR onto the latest master to allow for the GitHub Actions to run. You'll need to approve them once, though, because technically I'm a new contributor.

@jasonsaayman
Copy link
Member

@TimWolla thanks for being so tenacious, I am merging this now 🥳

@jasonsaayman jasonsaayman merged commit 4f25380 into axios:master Sep 5, 2021
@TimWolla
Copy link
Contributor Author

TimWolla commented Sep 5, 2021

Thanks! 🚀

mbargiel pushed a commit to mbargiel/axios that referenced this pull request Jan 27, 2022
This patch allows TypeScript users to extend the `Axios` class without
the type checker complaining.

see 7548f2f

Co-authored-by: Jay <jasonsaayman@gmail.com>
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.

Align auto-import with README examples
6 participants