Skip to content

feat(types): Allow the Params property to be typed, instead of any - #11081

Merged
jasonsaayman merged 14 commits into
axios:v1.xfrom
shaedrich:axios-request-config-params-generics-2026-edition
Jul 15, 2026
Merged

jasonsaayman merged 14 commits into
axios:v1.xfrom
shaedrich:axios-request-config-params-generics-2026-edition

Conversation

@shaedrich

@shaedrich shaedrich commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Note

If you, due to time constraints or otherwise, won't be able to review this PR within the next year, please just say so right away and save us all time and nerves. Thanks in advance.

Similar to/Follow-up to #1061

Resubmission of #6807

Summary

Currently, it is not possible to have AxiosRequestConfig.params correctly typed—it will always be any. This PR changes that.

Linked issue

Closes #4954

Changes

  • Makes AxiosRequestConfig.params generic, so it can be typed/the type be inferred

Checklist

  • Tests added or updated (or N/A with reason)
  • Docs/types updated if public API changed (index.d.ts and index.d.cts)
  • No breaking changes (or called out explicitly above)
  • The changes are not stale
  • The PR has a reviewer
  • The PR has no unaddressed feedback

Summary by cubic

Adds a params generic to axios request configs and propagates it across the public types for stronger typing and inference, with no runtime changes. Default request methods and AxiosPromise now preserve the request data and params types on response.config.

Description

  • Summary of changes
    • Added P to AxiosRequestConfig<D = any, P = any> and propagated to RawAxiosRequestConfig, InternalAxiosRequestConfig, AxiosDefaults, CreateAxiosDefaults, AxiosResponse<T, D, H, P>, AxiosError<T, D, P>, CanceledError<T, D, P>, isCancel<T, D, P>(), isAxiosError<T, D, P>(), all request aliases and callable AxiosInstance, adapters, AxiosPromise<T, D, P>, and mergeConfig<D, P>() in both ESM (index.d.ts) and CJS (index.d.cts).
    • Introduced an internal AxiosResponseDefault to keep existing generic positions; defaulted request aliases now return AxiosResponse<T, D, {}, P> so response.config.data and response.config.params mirror the request types.
    • Made CustomParamsSerializer<P> and ParamsSerializerOptions<P> generic and tied to the request params type; withXSRFToken callback now receives InternalAxiosRequestConfig<D, P>.
  • Reasoning
    • Type-safe query params and serializers, better inference in responses/errors/cancellation guards, and compatibility via P = any.
  • Additional context
    • Usage: AxiosRequestConfig<MyData, MyParams> or method aliases with trailing P, e.g. axios.get<T, R, D, P>(...).

Docs

  • Update TypeScript and API docs for AxiosRequestConfig<D, P>, generic CustomParamsSerializer<P>/ParamsSerializerOptions<P>, propagation to InternalAxiosRequestConfig, AxiosResponse, AxiosPromise<T, D, P>, AxiosError, CanceledError, isCancel, request aliases/callable instances, adapters, and mergeConfig<D, P>().
  • Add a short example showing typed params, a serializer receiving P, and defaulted alias/AxiosPromise responses preserving response.config.data/params; note P = any default and unchanged generic order.

Testing

  • Added/updated type-level tests (ESM/CJS) to verify:
    • params and serializers use P.
    • Propagation to InternalAxiosRequestConfig, AxiosResponse.config, AxiosError.config, and isCancel narrowing.
    • Method aliases, callable instances, AxiosPromise<T, D, P>, and mergeConfig preserve D and P.
    • Legacy untyped usage compiles; invalid param shapes error as expected.

Semantic version impact

Minor: additive typing changes with P = any default; no runtime changes.

Written for commit 5a0d082. Summary will update on new commits.

Review in cubic

Co-authored-by: willen leal <willenlealdev@gmail.com>

Resubmission of 499c9fc
@shaedrich
shaedrich requested a review from jasonsaayman as a code owner July 14, 2026 16:09
@shaedrich shaedrich changed the title feat(types): Add type generics to AxiosRequestConfig.params feat(types): Allow the Params property to be typed, instead of any Jul 14, 2026
@shaedrich shaedrich changed the title feat(types): Allow the Params property to be typed, instead of any feat(types): Allow the Params property to be typed, instead of any Jul 14, 2026

@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

@jasonsaayman

Copy link
Copy Markdown
Member

thanks @shaedrich i will be adding to the pr and then merging. we are now trying to get through pr's etc much faster than before

@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.

All reported issues were addressed across 8 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread docs/pages/advanced/api-reference.md Outdated
Comment thread docs/zh/pages/advanced/api-reference.md Outdated
Comment thread docs/zh/pages/advanced/api-reference.md Outdated
Comment thread docs/fr/pages/advanced/api-reference.md Outdated
Comment thread docs/zh/pages/advanced/api-reference.md Outdated
Comment thread docs/es/pages/advanced/api-reference.md Outdated
@shaedrich

shaedrich commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor Author

thanks @shaedrich i will be adding to the pr and then merging. we are now trying to get through pr's etc much faster than before

@jasonsaayman Thanks, appreciate it!

@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.

All reported issues were addressed across 14 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread index.d.cts
Comment thread index.d.cts Outdated
@jasonsaayman

Copy link
Copy Markdown
Member

@cubic-dev-ai please review in depth again

@cubic-dev-ai

cubic-dev-ai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai please review in depth again

@jasonsaayman I have started the AI code review. It will take a few minutes to complete.

@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.

All reported issues were addressed across 7 files

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

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

Re-trigger cubic

Comment thread index.d.cts
@jasonsaayman
jasonsaayman merged commit 3077e62 into axios:v1.x Jul 15, 2026
25 checks passed
@shaedrich
shaedrich deleted the axios-request-config-params-generics-2026-edition branch July 15, 2026 10:00
@jasonsaayman jasonsaayman added the commit::feat The PR is related to a feature label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::feat The PR is related to a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow the Params property to be typed, instead of any

2 participants