fix: correct isCancel type to narrow to CanceledError by Mohammad-Faiz-Cloud-Engineer · Pull Request #10952 · axios/axios (original) (raw)
The isCancel type guard in index.d.cts was returning value is Cancel which doesn't match the actual runtime isCancel checks for CanceledError, not Cancel. This updates it to value is CanceledError so TypeScript correctly narrows the type when using the guard.
Summary by cubic
Fixes axios.isCancel in CommonJS typings to narrow to CanceledError<T>, matching ESM and runtime, and adds CJS typing tests to verify narrowing and that the generic T is preserved.
Description
Use this section for review hints, explanations or discussion points.
- Summary of changes
- Update
index.d.ctstoisCancel<T = any>(value: any): value is CanceledError<T>; - Add CJS typing fixture asserting narrowing and generic preservation; run via
tsc --noEmit - Note the change in
PRE_RELEASE_CHANGELOG.md
- Update
- Reasoning
- Align CJS types with runtime and ESM and preserve generic response data
- Additional context
- Type-only change; may expose compile-time errors where
Cancelor widenedanywas assumed
- Type-only change; may expose compile-time errors where
Docs
Update /docs/ to show isCancel identifies CanceledError and keeps generic response types, with a short ESM and CJS example.
Testing
Added cjs-is-cancel-typing.ts and a typings.module.test.cjs case that compiles with tsc --noEmit, asserting both narrowing to CanceledError and generic T preservation. No runtime tests needed.
Semantic version impact
Patch: declaration fix aligning CommonJS types with existing runtime and ESM behavior.
Written for commit 4b89869. Summary will update on new commits.