Skip to content

Add lib types for JSON.rawJSON, JSON.isRawJSON, and reviver context#63248

Open
VedantMadane wants to merge 2 commits intomicrosoft:mainfrom
VedantMadane:feat/json-parse-with-source
Open

Add lib types for JSON.rawJSON, JSON.isRawJSON, and reviver context#63248
VedantMadane wants to merge 2 commits intomicrosoft:mainfrom
VedantMadane:feat/json-parse-with-source

Conversation

@VedantMadane
Copy link

@VedantMadane VedantMadane commented Mar 13, 2026

Adds es2025.json.d.ts with type definitions for the Stage 4 TC39 proposal-json-parse-with-source which is part of ES2025 and has shipped in all major browsers and Node.js 22+.

Summary

  • JSON.rawJSON(text) - creates a frozen RawJSON object for lossless JSON serialization (e.g. preserving large-integer precision)
  • JSON.isRawJSON(value) - type-guard that narrows to RawJSON
  • JSON.parse reviver context - overload whose reviver receives a third parameter { source: string } containing the original JSON source text of each primitive value

New files

File Purpose
src/lib/es2025.json.d.ts RawJSON interface + JSON augmentations
tests/cases/compiler/jsonParseWithSource.ts Compiler test exercising all three APIs
tests/baselines/reference/jsonParseWithSource.* Accepted baselines

Modified files

File Change
src/lib/es2025.d.ts /// <reference lib="es2025.json" />
src/lib/libs.json Register es2025.json
src/compiler/commandLineParser.ts Map es2025.json to its .d.ts

Fixes #61330

Adds esnext.json.d.ts with type definitions for the Stage 4 TC39
proposal-json-parse-with-source (shipped in all major browsers and
Node.js 22+):

- JSON.rawJSON(text): creates a RawJSON object for lossless serialization
- JSON.isRawJSON(value): type guard narrowing to RawJSON
- JSON.parse reviver context: third parameter with { source: string }

Fixes microsoft#61330
The proposal-json-parse-with-source is Stage 4 and part of ES2025,
so the lib should live in es2025.json.d.ts, not esnext.json.d.ts.
@Renegade334
Copy link
Contributor

which is part of ES2025

It isn't, MDN is wrong on this one. It has stage 4 approval, but is not yet in the latest draft: tc39/ecma262#3714

@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@RyanCavanaugh
Copy link
Member

Reopening as this is still valid (minus commandlineParser.ts)

@RyanCavanaugh RyanCavanaugh reopened this Mar 24, 2026
@github-project-automation github-project-automation bot moved this from Done to Not started in PR Backlog Mar 24, 2026
@RyanCavanaugh RyanCavanaugh added this to the Post-7.0 lib candidates milestone Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Support proposal-json-parse-with-source (JSON.rawJSON(), JSON.isRawJSON(), context parameter of reviver function, etc...)

4 participants