deno icon indicating copy to clipboard operation
deno copied to clipboard

lsp: incorrectly supports type checking of named imports of JSON modules

Open jeiea opened this issue 3 years ago • 6 comments

Deno language server (as vscode intellisense) prints no error, but deno run reject the following.

Reproducible steps

> deno --version
deno 1.17.1 (release, x86_64-pc-windows-msvc)
v8 9.7.106.15
typescript 4.5.2

test.json

{ "a": 3 }

test.ts

import { a } from "./test.json" assert { type: "json" };
console.log(a);
deno run --unstable -A ./test.ts

What I expected

Print 3

What I got

error: Uncaught SyntaxError: The requested module './test.json' does not provide an export named 'a'
import { a } from "./test.json" assert { type: "json" };
         ^

jeiea avatar Dec 27 '21 16:12 jeiea

Per spec this is not supported.

The json file that you are importing doesn't have to be an object.

4
"hello world"
[1, 2, 3]

All of the above examples are valid JSON and there's no way to make them work with destructuring syntax and thus it's not supported. (Also named imports are live bindings, whereas default import is not)

bartlomieju avatar Dec 27 '21 16:12 bartlomieju

It is also a design limitation about it being "acceptable" in Deno Language Server, though we should try harder to fix it if we can.

kitsonk avatar Dec 28 '21 09:12 kitsonk

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 Feb 26 '22 20:02 stale[bot]

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 Apr 28 '22 02:04 stale[bot]

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 Jun 27 '22 22:06 stale[bot]

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]

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 Nov 09 '22 07:11 stale[bot]