microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.17k stars 12.51k forks source link

Support import types in JSDoc links #43950

Open mjbvz opened 3 years ago

mjbvz commented 3 years ago

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

4.3.0-dev.20210503

💻 Code

For some JavaScript:

// foo.js

export class Foo {}
// index.js

/**
 * {@link import('./foo').Foo Foo}
 * 
 * @param {import('./foo').Foo} foo 
 */
function withFoo(foo) { }

🙁 Actual behavior

The parameter type is resolved but the @link is not

🙂 Expected behavior

Both links should be resolved

olee commented 3 years ago

Same issue for me - this is especially annoying, because TS and eslint regard type imports which are only used for JSDoc as unused and will request to remove those imports.

marcelocra commented 1 year ago

As a workaround, you could use typedef with an import, pointing the link to it:

/** @typedef {import("./typedefs.js").TheType} TheType */

/**
 * Some doc with a link to the type {@link TheType}.
 */

Not great, as "go to definition" will take you to this typedef instead of the main one, but at least the correct type is shown when hovering.

jespertheend commented 1 year ago

That will cause TheType to be exported twice though (#46011). I usually just end up not linking at all in this situation, because I'd rather not have duplicate entries in my autocomplete list.

ethanresnick commented 1 year ago

I would really love to see this too.

Today, I think the best solution is to manually alias the import to start with an _, and configure eslint to not flag variables as unused if they start with an _, but that aliasing is kinda annoying. The import will also still get removed by TS' organizeImports even with the alias.

optyler commented 11 months ago

I think my old issue is similar to this one...

I was trying to @link a function from an imported module from node_module

Per jsdoc documentation this should be possible

Link to a module (e.g. within a @link or @see tag) using "module:moduleName". For example, "@module foo/bar" can be linked to using "{@link module:foo/bar}".

I was expecting that these comments link to the function in node_module/date-fns/format but they just render as is

/**
  * @see module:date-fns/format
  * @link module:date-fns/format
  */
image
kravetsone commented 4 months ago

+1

Why i should import it in top of the module for simple JSDoc link?