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

lsp: unable to import types in JSDoc #11362

Closed
jaydenseric opened this issue Jul 12, 2021 · 3 comments
Closed

lsp: unable to import types in JSDoc #11362

jaydenseric opened this issue Jul 12, 2021 · 3 comments
Labels
duplicate a duplicate of another issue

Comments

@jaydenseric
Copy link

In regular TypeScript projects, within a .js file with type checking enabled via // @ts-check you can import types from other files within JSDoc comments. For example…

In a.js:

// @ts-check

/**
 * Description for A.
 * @param {import("./b.js").default} b The B.
 */
export default function a(b) {
  return b;
}

In b.js:

// @ts-check

/**
 * Description for B.
 * @type {boolean}
 */
export default true;

Note that the parameter type is able to be imported and checked:

Screen Shot 2021-07-12 at 10 43 26 am

With exactly the same setup in a Deno project, the parameter type cannot be imported or checked:

Screen Shot 2021-07-12 at 10 43 07 am

This not working in Deno, with no open issues about it has really made the past few days trying to get an isomorphic codebase with a mixture of .ts, .tsx, and .js files a nightmare, because it's hard to tell if it's you or Deno that's doing the wrong thing. I think if this Deno bug were fixed I'd finally have a workable solution!

@kitsonk kitsonk added bug Something isn't working correctly lsp related to the language server needs investigation requires further investigation before determining if it is an issue or not labels Jul 12, 2021
@kitsonk kitsonk changed the title Unable to import types in JSDoc lsp: unable to import types in JSDoc Jul 19, 2021
@jaydenseric
Copy link
Author

Has any investigation on this happened yet; is this an easy or hard bug to fix?

If it's a low-hanging fruit, patching this would be a game changer for those of us trying to develop and publish isomorphic library code with type safety. Type checking is practically impossible for universal browser/Deno modules until this is fixed.

@jaydenseric
Copy link
Author

Here is an example of a type importable in a .ts file:

import type { Context } from "https://deno.land/x/[email protected]/mod.ts";

Screen Shot 2021-10-04 at 6 27 13 pm

As you can see, attempting to import it for use in a JSDoc @typedef doesn't work:

// @ts-check
/** @typedef {import("https://deno.land/x/[email protected]/mod.ts").Context} Context */

Screen Shot 2021-10-04 at 6 29 05 pm

It is a really mysterious thing why importing types in JSDoc sometimes works, and sometimes doesn't. It seems to never work when you import a type from a .ts file into JSDoc in a .js file though.

This issue hasn't been investigated or fixed in the nearly 3 months since it was filed in June 😢

I'm sure in time Deno will shape up to be the dream JS/TS runtime and I appreciate the efforts of the Deno collaborators and contributors, but IMO the Deno team needs to focus more on unblocking package authors that are working hard pro-bono to build out packages to grow the Deno ecosystem. Bugs that are showstoppers for type checking (e.g. #11362 , #12143 , #11786 (comment)), code coverage (e.g. #11327), etc. need to be dealt with with a sense of urgency instead of working on enhancements or nice-to-haves like Node.js ecosystem compatibility. That way both the Deno runtime and a useful ecosystem of packages can be developed in parallel, and the Deno API can evolve sooner to meet the needs of package authors.

@kitsonk kitsonk added duplicate a duplicate of another issue and removed bug Something isn't working correctly needs investigation requires further investigation before determining if it is an issue or not lsp related to the language server labels Dec 21, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Dec 21, 2021

Even though #13156 came long after, @jespertheend was able to isolate it in that issue, and changes are being made to fix the issue, so we will use #13156 for tracking purposes.

Closing this as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants