Repository: TypeScript
Issue: JSON modules without "allowSyntheticDefaultImports"
Labels: Suggestion,Experience Enhancement

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

`allowSyntheticDefaultImports` `resolveJsonModule` `esnext` `TS1259`

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

Importing JSON files should be permitted when the following options are used:

- `module: esnext`
- `resolveJsonModule: true`
- `allowSyntheticDefaultImports: false`

Whereas currently this does not work.  Instead the JSON import site errors with:
`TS1259: Module 'data.json' can only be default-imported using the 'allowSyntheticDefaultImports' flag`

## 📃 Motivating Example

```ts repro
// @target: esnext
// @module: esnext
// @resolveJsonModule: true
// @allowSyntheticDefaultImports: false
                               // ^^^^^ enabling this eliminates the error

import json from "./data.json" assert { type: "json" };
              // ^ Error TS1259 - cannot import!
json;


// @filename: data.json
{ "name": "jason" }
```

[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?target=99&allowSyntheticDefaultImports=false&resolveJsonModule=true&ts=4.6.0-dev.20220116#code/PTAEAEBcEMCcHMCmkBcpEGcB2iAekAoECAWwHsATAVwBtE1Md8ixxZMyaA3RAKQzJYAspVqIWEaDRpkA7gGUAnlkgALZAEsAxgBFEAM2i1IASRIAHMrEgY0hmhnGhnL12-ceXxAHq-f6LGgAIxoNLHhQNQ0MdFCSMOhITEj1dFhYKwICDQsrSFAAKwEsUH0MklAAIgA6YApE6GqiwUrQaAxHa1AAb0jFc3oq5qxWgF8AbgJPdx9QAFF0q1AAFXkARgAmAFYATlAAWlAtaCwsMnycy2sAQgJhyazicH0NOkCSQfqYJuKCXsr3ohKmhKgV2i1QKMgA)

## 💻 Use Cases

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->

Importable JSON modules are becoming popular.  Chrome 91 has support.  [Node 17.5.0 has support](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V17.md#17.5.0) thanks to @GeoffreyBooth.  @weswigham is [about to add support in TypeScript](https://github.com/microsoft/TypeScript/issues/47819) for the scenario of `module: nodenext && resolveJsonModule: true`

This request is a slightly different ask.  I'd like to use JSON modules with a vanilla JavaScript runtime unrelated to Node and unrelated to Wes's work to support Node's integration of ESM.  Seems like [Deno is also affected by this](https://github.com/denoland/deno/issues/13098) - maybe CloudFlare Workers might benefit from this too?  Anyone directly targeting a browser could benefit too.  Hence sticking to `module: esnext`

The only workaround available today to make JSON modules work with `module: esnext` is to also enable `allowSyntheticDefaultImports`.  This is an unfortunate **coupling of concerns** because enabling `allowSyntheticDefaultImports` reduces type-safety - it permits code to accidentally use non-existent exports without erroring at build-time.  So I'd like to turn `allowSyntheticDefaultImports` off.

The coupling of `resolveJsonModule` with `allowSyntheticDefaultImports` has existed for many years, hence I'm raising this as a feature request rather than a bug.