Skip to content

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

Open
VedantMadane wants to merge 5 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 5 commits intomicrosoft:mainfrom
VedantMadane:feat/json-parse-with-source

Conversation

@VedantMadane
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
RyanCavanaugh noted this PR is still valid minus commandlineParser.ts.
Revert commandLineParser.ts to match upstream main.
ArshVermaGit

This comment was marked as spam.

Copilot AI review requested due to automatic review settings April 16, 2026 07:39
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an ES2025-by-feature lib file to type the now-standard JSON.rawJSON, JSON.isRawJSON, and the JSON.parse reviver “source context” capability, and wires it into the es2025 lib plus compiler test coverage.

Changes:

  • Introduces src/lib/es2025.json.d.ts defining RawJSON and augmenting JSON with rawJSON, isRawJSON, and a JSON.parse overload with a context parameter.
  • References the new lib from src/lib/es2025.d.ts and registers es2025.json in src/lib/libs.json.
  • Adds a compiler test (jsonParseWithSource.ts) and accepted baselines covering all three APIs.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/lib/es2025.json.d.ts Adds RawJSON and JSON API typings for the ES2025 JSON additions.
src/lib/es2025.d.ts Includes the new es2025.json lib in the es2025 umbrella lib.
src/lib/libs.json Registers es2025.json as an available by-feature lib.
tests/cases/compiler/jsonParseWithSource.ts Compiler test exercising rawJSON, isRawJSON, and reviver context.
tests/baselines/reference/jsonParseWithSource.types Baseline for type printing of the new APIs.
tests/baselines/reference/jsonParseWithSource.symbols Baseline for symbol resolution including the new lib.
tests/baselines/reference/jsonParseWithSource.js Baseline for JS emit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

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

6 participants