Skip to content

fix(types): align interceptor handler runWhen typing#7464

Open
theamodhshetty wants to merge 1 commit intoaxios:v1.xfrom
theamodhshetty:codex/fix-runwhen-types
Open

fix(types): align interceptor handler runWhen typing#7464
theamodhshetty wants to merge 1 commit intoaxios:v1.xfrom
theamodhshetty:codex/fix-runwhen-types

Conversation

@theamodhshetty
Copy link

@theamodhshetty theamodhshetty commented Mar 3, 2026

Summary

This fixes an inconsistency between request interceptor option typing and the internal request interceptor handler typing.

Before this change:

  • AxiosInterceptorOptions['runWhen'] was typed as (config: InternalAxiosRequestConfig) => boolean
  • AxiosInterceptorManager['handlers'][number]['runWhen'] was typed differently in index.d.ts / index.d.cts

That mismatch can cause assignability issues when working with AxiosInstance types across module boundaries.

This patch:

  • aligns AxiosInterceptorHandler['runWhen'] to AxiosInterceptorOptions['runWhen'] | null in both index.d.ts and index.d.cts
  • adds typings coverage in both ESM and CJS typings tests to ensure handler and options runWhen types stay compatible

Fixes #7404.

Testing

  • npm test --prefix test/module/typings/esm
  • npm test --prefix test/module/typings/cjs

Summary by cubic

Aligns the interceptor handler runWhen type with AxiosInterceptorOptions to prevent assignability errors across module boundaries. Adds ESM and CJS typing tests to lock the contract.

Description

  • Summary of changes
    • Set AxiosInterceptorHandler['runWhen'] to AxiosInterceptorOptions['runWhen'] | null in index.d.ts and index.d.cts.
    • Added minimal ESM/CJS typing tests asserting handler and options runWhen compatibility.
  • Reasoning
    • Handler and option runWhen types diverged, causing type errors when sharing AxiosInstance types between modules.
  • Additional context

Docs

No docs changes needed. This only aligns TypeScript typings.

Testing

  • Added compile-time tests in:
    • test/module/typings/esm/index.ts
    • test/module/typings/cjs/index.ts
  • How to run:
    • npm test --prefix test/module/typings/esm
    • npm test --prefix test/module/typings/cjs
  • No runtime tests required for this types-only fix.

Written for commit 8ec423f. Summary will update on new commits.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

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

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.

issue in runWhen types

1 participant