如何在 comments/JSDoc 中引用另一个打字稿类型?

How do I refer to another typescript type in comments/JSDoc?

我熟悉 Javadoc。在 Javadoc 中,you can place a link that refers to the Javadoc placed on another type 像这样:

/**
 * some java thingy. see this other java thingy too {@link OtherThingy}
 */
public class Thingy { /*...*/ }

/**
 * some other java thingy. see the first java thingy too {@link Thingy}
 */
public class OtherThingy{ /*...*/ }

我可以在 JSDoc 的打字稿风格中做同样的事情吗?我知道我可以在评论中使用 markdown,我可以放置网络链接,但这并不是我想要的。

此外,任何对 JSDoc/typescript 文档工具的引用都会非常有帮助:)

编辑:根据下面的回答,这是 JSDoc 的一个特性,但似乎没有包含在 VSCode 中。 VSCode 中是否存在有效语法?

你当然可以,尽管你的里程可能会有所不同。

1: A use of @link in Selenium-Webdriver's TypeScript typing file

/**
 * Converts a level name or value to a {@link logging.Level} value.
 * If the name/value is not recognized, {@link logging.Level.ALL}
 * will be returned.
 * @param {(number|string)} nameOrValue The log level name, or value, to
 *     convert .
 * @return {!logging.Level} The converted level.
 */
function getLevel(nameOrValue: string | number): Level;

2: Docs about @link in JSDoc

The following example shows all of the ways to provide link text for the {@link} tag: Providing link text

/**
 * See {@link MyClass} and [MyClass's foo property]{@link MyClass#foo}.
 * Also, check out {@link http://www.google.com|Google} and
 * {@link https://github.com GitHub}.
 */
function myFunction() {}

By default, the example above produces output similar to the following: Output for {@link} tags

See <a href="MyClass.html">MyClass</a> and <a 
href="MyClass.html#foo">MyClass's foo
property</a>. Also, check out <a 
href="http://www.google.com">Google</a> and
<a href="https://github.com">GitHub</a>.

VS Code 将 {@link} 视为注释,因此不会进行任何特殊解析(它只是按照您键入的方式显示)。不过,目前 an open issue 可以解决此问题。

随着 VSCode 1.52(2020 年 11 月),您可能还会考虑另一个标签:

Initial support for JSDoc @see tags

JSDoc @see tags let you reference other functions and classes in your JSDoc comments.

The example below shows crash function referencing the WrappedError class from another file:

// @filename: somewhere.ts
export class WrappedError extends Error { ... }

// @filename: ace.ts
import { WrappedError } from './somewhere'

/**
* @see {WrappedError}
*/
function crash(kind) {
   throw new WrappedError(kind);
}

VS Code will now include basic @see references while performing renames.

You can also run go to definition on the @see tag's content and @see tags will also show up in the list of references.

We plan to continue improving support for @see tags in future releases.

正如马克在 中指出的那样:

  • PR 119358 在 VSCode 1.55(2021 年 3 月)
  • 中添加了对 JSDoc link 标签的支持
  • VSCode 1.57(2021 年 5 月)adds @link support

JSDoc @link support

We now support JSDoc @link tags in JavaScript and TypeScript comments.

These let you create clickable links to a symbol in your documentation:

JSDoc @link tags are written as: {@link symbolName}.

You can also optionally specify text to be render in place of the symbol name: {@link class.property Alt text}.

@link is supported in hovers, suggestions, and signature help.
We have also updated vscode.d.ts to use @link.