Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for JSDoc @import #25516

Open
mayank99 opened this issue Sep 8, 2024 · 4 comments · May be fixed by #26991
Open

support for JSDoc @import #25516

mayank99 opened this issue Sep 8, 2024 · 4 comments · May be fixed by #26991
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler

Comments

@mayank99
Copy link

mayank99 commented Sep 8, 2024

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" */
@mayank99
Copy link
Author

mayank99 commented Sep 8, 2024

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 mayank99 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
@FND
Copy link

FND commented Oct 18, 2024

@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

@mayank99
Copy link
Author

Ah true, I hadn't considered type checking (although I mentioned type declarations). I'll reopen it.

@mayank99 mayank99 reopened this Oct 18, 2024
@FND
Copy link

FND commented Oct 18, 2024

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)

@dsherret dsherret added feat new feature (which has been agreed to/accepted) bug Something isn't working correctly tsc related to the TypeScript tsc compiler and removed feat new feature (which has been agreed to/accepted) labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly tsc related to the TypeScript tsc compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants