deno icon indicating copy to clipboard operation
deno copied to clipboard

Cannot import JSON module as type

Open alex-kinokon opened this issue 2 years ago • 2 comments

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" };

alex-kinokon avatar Jun 20 '22 03:06 alex-kinokon

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.

nayeemrmn avatar Jun 20 '22 03:06 nayeemrmn

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.

stale[bot] avatar Sep 08 '22 21:09 stale[bot]