fix(types): make parseReviver context.source optional per ES2023 spec#10837
Merged
jasonsaayman merged 2 commits intoMay 6, 2026
Merged
Conversation
Per the TC39 proposal-json-parse-with-source, context.source is only
set when the reviver is invoked on a primitive value (string, number,
boolean, null). For object/array values, source is absent from the
context object.
Changed context?: { source: string } to context?: { source?: string }
in both index.d.ts and index.d.cts.
Fixes axios#10817
jasonsaayman
approved these changes
May 6, 2026
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.
Background
PR #10782 added the ES2023
contextargument to theparseRevivertype:This is correct as far as it goes, but is slightly looser than the spec.
The Gap
Per the TC39 proposal-json-parse-with-source,
context.sourceis only set when the reviver is invoked on a primitive value (string, number, boolean, null). When the reviver is invoked on an object or array,sourceis absent from the context object.The current typing says "if
contextis provided,sourceis always a string." That's true for primitives but not for object/array reviver invocations. A user can legally write:Fix
Mark
sourceas optional:Applied to both
index.d.tsandindex.d.cts.Fixes #10817
Summary by cubic
Make
parseRevivercontextsourceoptional inAxiosRequestConfigto match ES2023JSON.parsewith source. Corrects typing that impliedsourcewas always present; no runtime changes.Description
parseRevivertype tocontext?: { source?: string }inindex.d.tsandindex.d.cts.v1.xwith no additional functional changes.context.sourceonly for primitive values; it’s absent for objects/arrays.context?.sourcebefore use.Docs
/docs/to notecontext.sourceis optional and present only for primitives, with a short guarded example.Testing
context.sourceis optional and narrows with guards.Semantic version impact
Patch: typings corrected to match the spec; no runtime API changes.
Written for commit f9372e5. Summary will update on new commits.