[Docs/Types] Update parseReviver TypeScript definitions for ES2023 and add to official configuration documentation#10782
Conversation
There was a problem hiding this comment.
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, theparseReviversample may throw whenBigInt(context.source)receives non-integer or exponent-form numbers afterNumber.isSafeIntegerfails, which can mislead users copying the example. docs/pages/advanced/request-config.mdusesTemporalwithout an availability guard, so example code can fail in environments whereTemporalis 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.
5787522 to
9fbebb9
Compare
9fbebb9 to
b1457df
Compare
|
@cubic-dev-ai please review again |
@jasonsaayman I have started the AI code review. It will take a few minutes to complete. |
9125b30 to
da8ad4e
Compare
|
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! |
8b0ffae to
bb2f6ac
Compare
bb2f6ac to
26b3074
Compare
|
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? |
Description:
Currently, Axios passes the
parseReviverconfiguration option directly to the nativeJSON.parsefunction under the hood (e.g.,return JSON.parse(data, own(this, 'parseReviver'));). However, there are two issues regarding its discoverability and TypeScript support:parseReviveroption is completely absent from the Request Config documentation.parseReviverdoes not support the ES2023/ES14 standard, which introduces a thirdcontextargument to the reviver function (specifically forcontext.source).Expected Behavior:
1. Documentation:
parseRevivershould be listed in the Request Config docs alongsidetransformResponse, explaining that it allows users to provide a custom reviver function toJSON.parse.2. TypeScript Definitions:
The
index.d.tsfile 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 (likeTemporal).Current Type:
Proposed Type:
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.
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:
Proposed Solution:
parseReviverindocs/req_config.md.parseReviversignature inindex.d.tsto include the optionalcontextparameter.Summary by cubic
Adds ES2023
context.sourcesupport to theparseReviverTypeScript type and documents safe usage (BigInt and optionalTemporal). No runtime changes toaxios.Description
index.d.tsandindex.d.ctstoparseReviver?: (this: any, key: string, value: any, context?: { source: string }) => any.parseReviversection to/docs/pages/advanced/request-config.mdwith precision-safe BigInt parsing and guardedTemporalhydration; fix a minor formatting issue (trailing comma in examples).parseReviverexample showing precision-safe BigInt parsing.JSON.parserevivercontextand surfaces safe parsing patterns.parseReviveris passed to nativeJSON.parseby the defaulttransformResponse.Docs
Update the docs site in
/docs/to include the newparseReviversection and examples, and ensure the README references remain consistent.Testing
tsd/dtslintassertions for(key, value, context?)andcontext.source: stringin both.d.tsand.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