fix(types): align runWhen type with runtime behavior in InterceptorManager#7529
Open
techcodie wants to merge 1 commit intoaxios:v1.xfrom
Open
fix(types): align runWhen type with runtime behavior in InterceptorManager#7529techcodie wants to merge 1 commit intoaxios:v1.xfrom
techcodie wants to merge 1 commit intoaxios:v1.xfrom
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 4/5
- This PR looks safe to merge overall, with one moderate typing mismatch rather than a clear runtime break.
- In
index.d.cts,AxiosInterceptorHandler.runWhenis typed too narrowly; at runtime it can beundefinedwhen interceptor options are passed withoutrunWhen, which can cause TypeScript consumers to see incorrect type expectations. - Given the issue is medium severity (5/10) and limited to declaration typing, risk appears contained but worth a follow-up fix to keep typings aligned with runtime behavior.
- Pay close attention to
index.d.cts- ensurerunWhenallowsundefinedto match actual runtime assignment.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="index.d.cts">
<violation number="1" location="index.d.cts:652">
P2: `AxiosInterceptorHandler.runWhen` type is too narrow: runtime can set it to `undefined` when options are provided without `runWhen`.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…nager The `runWhen` property in `AxiosInterceptorOptions` and `AxiosInterceptorHandler` had type inconsistencies that caused TypeScript build failures when upgrading from axios 1.13.2 to 1.13.5+. Issues fixed: 1. `AxiosInterceptorOptions.runWhen` did not allow `null`, but `InterceptorManager.use()` explicitly sets it to `null` when no options are provided (`runWhen: options ? options.runWhen : null`). 2. `AxiosInterceptorHandler.runWhen` used `AxiosRequestConfig` instead of `InternalAxiosRequestConfig`, creating a type mismatch with `AxiosInterceptorOptions` which uses `InternalAxiosRequestConfig`. 3. In `index.d.ts`, the `AxiosInterceptorHandler.runWhen` type was `(config: AxiosRequestConfig) => boolean | null` — the `| null` was incorrectly placed as part of the return type rather than making the entire function type nullable. 4. `AxiosInterceptorHandler.runWhen` is now optional (`?`) to also allow `undefined`, matching the runtime case where options are passed without a `runWhen` property (i.e. `options.runWhen` is `undefined`). Fixes axios#7404
6951273 to
bcddc76
Compare
Contributor
Author
|
Addressed the review feedback — Changes are backward compatible and fix the TypeScript build failures reported in #7404. This PR is ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7404
The
runWhenproperty inAxiosInterceptorOptionsandAxiosInterceptorHandlerhad type inconsistencies that caused TypeScript build failures when upgrading from axios1.13.2to1.13.5+.Problems Fixed
1.
AxiosInterceptorOptions.runWhendid not allownullInterceptorManager.use()explicitly setsrunWhentonullwhen no options are provided:But the type definition did not reflect this:
2.
AxiosInterceptorHandler.runWhenused wrong config typeThe handler type used
AxiosRequestConfigwhileAxiosInterceptorOptionsusedInternalAxiosRequestConfig. SinceInterceptorManagerreceives itsrunWhendirectly from the options, both should useInternalAxiosRequestConfig.3. Incorrect
nullplacement inindex.d.tsIn
index.d.ts, the type was:This means "a required function that returns
boolean | null", but the actual runtime value is "a function ORnull":4.
AxiosInterceptorHandler.runWhennow allowsundefinedWhen
optionsis provided without arunWhenproperty,options.runWhenevaluates toundefined. The type is now optional (?) to allow bothnull(no options passed) andundefined(options passed withoutrunWhen).Files Changed
index.d.tsAxiosInterceptorOptions.runWhenandAxiosInterceptorHandler.runWhentypesindex.d.ctsHow It Was Verified
lib/core/InterceptorManager.js(line 24) setsrunWhentonulllib/core/Axios.js(line 145) checkstypeof interceptor.runWhen === 'function', safely handlingnullandundefinedrunWhenas a function continues to work