denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.03k stars 5.23k forks source link

Cannot import JSON module as type #14913

Open alex-kinokon opened 2 years ago

alex-kinokon commented 2 years ago

Bug report

There doesn’t seem to be a way to import a JSON module purely as type.

Minimum reproduction:

// error: Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import assertion with the type of "json".
import type * as t from "./a.json";

Linter will also report a no-assert-type error. However, if you add the assertion as suggested by the linter, you get:

// error: TS2822 [ERROR]: Import assertions cannot be used with type-only imports or exports.
import type * as t from "./a.json" assert { type: "json" };
nayeemrmn commented 2 years ago

I guess it makes sense that TS doesn't like import assertions on type-only imports, they don't serve their purpose in that context. Accordingly deno_graph shouldn't enforce assertions (or lack thereof) on type-only imports.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.