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

时间:2017-06-01 11:21:53

标签: typescript visual-studio-code 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中是否有有效的语法?

3 个答案:

答案 0 :(得分:9)

VS Code将{@link}视为注释,因此它不会得到任何特殊的解析(它只是按您键入的方式显示)。但是,目前有Retrying Background Functions可以解决此问题。

答案 1 :(得分:5)

你确定可以,但你的里程可能会有所不同。

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

2:Docs about @link in JSDoc

链接破坏时链接内容

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

  

以下示例显示了为{@link}标记提供链接文本的所有方法:   提供链接文字

/**
 * 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() {}
     

默认情况下,上面的示例生成类似于以下内容的输出:   {@link}标签的输出

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>.

答案 2 :(得分:1)

使用VSCode 1.52(2020年11月),您还可以考虑使用另一个标签:

Initial support for JSDoc @see tags

JSDoc @see标签可让您在JSDoc注释中引用其他函数和类。

以下示例显示了从另一个文件引用WrappedError类的崩溃函数:

// @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现在在执行重命名时将包含基本的@see参考。

您还可以在@see标记的内容上运行go to definition,@ see标记也将显示在引用列表中。

我们计划在将来的版本中继续改善对@see标签的支持。

相关问题