Skip to content

Add support for importing JSON modules "as const" - #64301

Open
James Prevett (james-pre) wants to merge 2 commits into
microsoft:mainfrom
james-pre:json-const-import
Open

James Prevett (james-pre) wants to merge 2 commits into
microsoft:mainfrom
james-pre:json-const-import

Conversation

@james-pre

Copy link
Copy Markdown

This PR implements importing JSON modules with const context, which has the same effect as an as const assertion.

This was discussed in #32063. The issue suggests using a const import attribute, however this PR uses a compiler option which is much simpler and should be more maintainable.

This feature is opt-in, so no existing code will be broken. It can be enabled by setting compilerOptions.importJsonAsConst to true in tsconfig.

Fixes #32063. Note this is the same work from microsoft/typescript-go#2539 and #63008.

Copilot AI balanced review requested due to automatic review settings September 16, 2026 21:21
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 16, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 16, 2026
@typescript-automation

Copy link
Copy Markdown

The TypeScript team hasn't accepted the linked issue #32063. If you can get it accepted, this PR will have a better chance of being reviewed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@james-pre James Prevett (james-pre) changed the title Json const import Add support for importing JSON modules "as const" Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

import ConstJson from './config.json' as const;

2 participants