Skip to content

[Docs/Types] Update parseReviver TypeScript definitions for ES2023 and add to official configuration documentation#10782

Merged
jasonsaayman merged 5 commits intoaxios:v1.xfrom
Raymondo97:feat/types-parse-reviver-context
Apr 29, 2026
Merged

[Docs/Types] Update parseReviver TypeScript definitions for ES2023 and add to official configuration documentation#10782
jasonsaayman merged 5 commits intoaxios:v1.xfrom
Raymondo97:feat/types-parse-reviver-context

Conversation

@Raymondo97
Copy link
Copy Markdown
Contributor

@Raymondo97 Raymondo97 commented Apr 20, 2026

Description:

Currently, Axios passes the parseReviver configuration option directly to the native JSON.parse function under the hood (e.g., return JSON.parse(data, own(this, 'parseReviver'));). However, there are two issues regarding its discoverability and TypeScript support:

  1. Missing from Documentation: The parseReviver option is completely absent from the Request Config documentation.
  2. Outdated TypeScript Definitions: The type definition for parseReviver does not support the ES2023/ES14 standard, which introduces a third context argument to the reviver function (specifically for context.source).

Expected Behavior:

1. Documentation:
parseReviver should be listed in the Request Config docs alongside transformResponse, explaining that it allows users to provide a custom reviver function to JSON.parse.

2. TypeScript Definitions:
The index.d.ts file should be updated to reflect modern JavaScript engine capabilities. The third argument allows developers to access the raw JSON source, which is critical for parsing large integers (BigInt) without precision loss or properly hydrating strict date types (like Temporal).

Current Type:

parseReviver?: (this: any, key: string, value: any) => any;

Proposed Type:

parseReviver?: (this: any, key: string, value: any, context?: { source: string }) => any;

Steps To Reproduce / Motivation:

When attempting to use modern ES2023 features to hydrate data at the network edge, TypeScript throws an error because the Axios types do not recognize the third argument.

const apiClient = axios.create({
  baseURL: '/api',
  parseReviver: (key, value, context) => { // TS Error: Expected 2 arguments, but got 3.
    // Use case: Prevent BigInt precision loss from backend systems
    if (typeof value === 'number' && context?.source && context.source.length > 15) {
       return BigInt(context.source);
    }
    return value;
  }
});

Currently, developers have to manually cast the function to bypass the Axios type definitions, even though the native JS engine executes the code perfectly.

Environment:

  • Axios Version: 1.15.1
  • Node.js/Browser: Node 20+ / Chrome 114+ / Modern Browsers (ES2023 support)
  • TypeScript Version: 5.9.3

Proposed Solution:

  • Add a brief entry for parseReviver in docs/req_config.md.
  • Update the parseReviver signature in index.d.ts to include the optional context parameter.

Summary by cubic

Adds ES2023 context.source support to the parseReviver TypeScript type and documents safe usage (BigInt and optional Temporal). No runtime changes to axios.

Description

  • Summary of changes
    • Types: update index.d.ts and index.d.cts to parseReviver?: (this: any, key: string, value: any, context?: { source: string }) => any.
    • Docs: add a parseReviver section to /docs/pages/advanced/request-config.md with precision-safe BigInt parsing and guarded Temporal hydration; fix a minor formatting issue (trailing comma in examples).
    • README: add a parseReviver example showing precision-safe BigInt parsing.
  • Reasoning
    • Aligns with ES2023 JSON.parse reviver context and surfaces safe parsing patterns.
  • Additional context
    • parseReviver is passed to native JSON.parse by the default transformResponse.

Docs

Update the docs site in /docs/ to include the new parseReviver section and examples, and ensure the README references remain consistent.

Testing

  • No tests added.
  • Recommend adding tsd/dtslint assertions for (key, value, context?) and context.source: string in both .d.ts and .d.cts. No runtime tests needed.

Semantic version impact

Patch: types and docs only; no runtime behavior changes.

Written for commit 8df2d9e. Summary will update on new commits. Review in cubic

Copy link
Copy Markdown
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.

2 issues found across 4 files

Confidence score: 4/5

  • This PR looks safe to merge overall, with risk concentrated in documentation examples rather than core runtime code, and the reported severities are moderate (5/10 and 4/10).
  • Most severe issue: in README.md, the parseReviver sample may throw when BigInt(context.source) receives non-integer or exponent-form numbers after Number.isSafeInteger fails, which can mislead users copying the example.
  • docs/pages/advanced/request-config.md uses Temporal without an availability guard, so example code can fail in environments where Temporal is unsupported.
  • Pay close attention to README.md, docs/pages/advanced/request-config.md - docs examples may throw at runtime in common unsupported/edge numeric parsing scenarios.
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="docs/pages/advanced/request-config.md">

<violation number="1" location="docs/pages/advanced/request-config.md:49">
P2: Docs example uses `Temporal` without availability guard, which can cause runtime parse failures in unsupported environments.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:436">
P2: The `parseReviver` example can throw by calling `BigInt(context.source)` for non-integer or exponent-form numbers when `Number.isSafeInteger` is false.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread docs/pages/advanced/request-config.md
Comment thread README.md Outdated
@Raymondo97 Raymondo97 force-pushed the feat/types-parse-reviver-context branch from 5787522 to 9fbebb9 Compare April 20, 2026 21:18
nidhishgajjar

This comment was marked as spam.

@Raymondo97 Raymondo97 force-pushed the feat/types-parse-reviver-context branch from 9fbebb9 to b1457df Compare April 21, 2026 15:55
@jasonsaayman
Copy link
Copy Markdown
Member

@cubic-dev-ai please review again

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 22, 2026

@cubic-dev-ai please review again

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

Copy link
Copy Markdown
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.

@Raymondo97 Raymondo97 force-pushed the feat/types-parse-reviver-context branch 3 times, most recently from 9125b30 to da8ad4e Compare April 23, 2026 18:09
@Raymondo97
Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to look at this! I’m new to contributing to open source, so I appreciate your patience while I worked through the commit signing and rebase process.

The PR should be in a clean, verified state now. This addition to parseReviver has been working great in my local development for handling high-precision numbers and Temporal types. Happy to make any further adjustments if needed!

@Raymondo97 Raymondo97 force-pushed the feat/types-parse-reviver-context branch 4 times, most recently from 8b0ffae to bb2f6ac Compare April 27, 2026 16:56
@Raymondo97 Raymondo97 force-pushed the feat/types-parse-reviver-context branch from bb2f6ac to 26b3074 Compare April 27, 2026 16:58
@Raymondo97
Copy link
Copy Markdown
Contributor Author

Raymondo97 commented Apr 27, 2026

I've noticed that if I try to keep the branch up to date, it resets the checks. Would you want me to continue trying to keep it up to date? Or will you just merge it as-is once the checks finish?

@jasonsaayman jasonsaayman merged commit 0fe3a5f into axios:v1.x Apr 29, 2026
22 checks passed
@Raymondo97 Raymondo97 deleted the feat/types-parse-reviver-context branch April 29, 2026 19:32
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.

3 participants