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

1 participant