-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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(types): change the type guard on isCancel #5595
base: v1.x
Are you sure you want to change the base?
Conversation
… to `CanceledError<any>`. This makes more sense as it reflects what `isCancel` is actually doing. In fact, if I'm not mistaken, the `Cancel` type is no longer in the project. It got removed in 7f12366. It should probably also be removed from the types.
Encountered this problem too. @DigitalBrainJS Mind taking a look at this PR when you're free? The |
Also /cc @jasonsaayman @mzabriskie. Thanks for the effort you put into this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if this makes sense! I think it would be a nice improvement while keeping the changes minimal. Overall though, great work on the PR - appreciate you submitting the fix!
Thanks to @samavati for the suggestion. Co-authored-by: Ehsan Samavati <samaavaati@gmail.com>
Thanks for your suggestion! I've added it to the PR. |
This fixes #5153.
Change the type guard on
isCancel
toCanceledError<any>
. This makes more sense as it reflects whatisCancel
is actually doing. In fact, if I'm not mistaken, theCancel
type is no longer in the project. It got removed in 7f12366. It should probably also be removed from the types, but I didn't do it in this PR, as I wanted to keep the change minimal.I needed to declare
name
onCanceledError
because the typesCanceledError
andAxiosError
need to be structurally different from each other in order for the type guard onisCancel
to work properly. From the point of view of TypeScript, declaringCanceledError
without introducing some new structure is a mistake, as both types are essentially aliases now. (TS is a structural typing system.) I did not opt to make__CANCEL__: boolean
part ofCanceledError
's structure, as that seemed counterintuitive. I don't think users of this library should necessarily know it exists or rely on its existence.