support for JSDoc `@import`
TypeScript 5.5 adds support for @import in JSDoc comments. It would be great if Deno could also support this.
/** @import { SomeType } from "npm:some-module" */
Actually it looks like this is automatically handled by VSCode (and maybe other IDEs) but only in JS files. The only minor issue is a linter warning "All imports in import declaration are unused. deno-ts(6192)" when hovering the comment.
It's possible that Deno might still need to add proper support for @import if someone wants to generate type declarations, but for now I'd say no action is needed.
@mayank99, please allow me to pick this up again. I'm not quite sure what you're referring to when you say "this is automatically handled by VSCode": Am I correct in assuming your type checking only happens within VSCode?
As far as I can tellยน, Deno itself (via deno check on the command line) does not yet support @import, as confirmed by another user. This seems like a significant discrepancy vis-ร -vis TypeScript's official tooling (including the language server used by IDEs), so I believe your original post remains a valid issue.
ยน tested with Deno 2.0.1 / TypeScript 5.6.2
Ah true, I hadn't considered type checking (although I mentioned type declarations). I'll reopen it.
Thanks, I appreciate that.
Just to confirm, and perhaps to simplify analysis, here's a reduced test case - starting with a single JS file to make sure type checking itself works as expected:
๐ index.js
/** @typedef {string | null} Entry */
/** @type {Entry[]} */
const items = [];
items.push("hello");
items.push(null);
items.push(123); // ๐ฅ
๐ tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"strict": true
}
}
$ deno check --config ./tsconfig.json ./index.js
error: TS2345 [ERROR]: Argument of type '123' is not assignable to parameter of type 'Entry'.
After moving this type definition into a separate file, Deno falsely reports everything's fine:
๐ index.js
/** @import { Entry } from "./util.js" */
/** @type {Entry[]} */
const items = [];
items.push("hello");
items.push(null);
items.push(123); // ๐ฅ
๐ util.js
/** @typedef {string | null} Entry */
$ deno check --config ./tsconfig.json ./index.js && echo OK
OK
If we now replace that @import line with an old-style @typedef import, Deno correctly reports the type error again:
/** @typedef {import("./util.js").Entry} Entry */
(tested with both Deno 1.46.3 and 2.0.1)