Skip to content

fix: correct isCancel type to narrow to CanceledError<T>#10952

Merged
jasonsaayman merged 4 commits into
axios:v1.xfrom
Mohammad-Faiz-Cloud-Engineer:fix/isCancel-type
May 28, 2026
Merged

fix: correct isCancel type to narrow to CanceledError<T>#10952
jasonsaayman merged 4 commits into
axios:v1.xfrom
Mohammad-Faiz-Cloud-Engineer:fix/isCancel-type

Conversation

@Mohammad-Faiz-Cloud-Engineer

@Mohammad-Faiz-Cloud-Engineer Mohammad-Faiz-Cloud-Engineer commented May 27, 2026

Copy link
Copy Markdown
Contributor

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.cts to isCancel<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
  • Reasoning
    • Align CJS types with runtime and ESM and preserve generic response data
  • Additional context
    • Type-only change; may expose compile-time errors where Cancel or widened any was assumed

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.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/module/cjs/tests/helpers/cjs-is-cancel-typing.ts
@jasonsaayman jasonsaayman merged commit a2390a5 into axios:v1.x May 28, 2026
25 checks passed
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.

2 participants