@example
标签类型: 块标签
TSDoc 标准化: 扩展
指示一个文档部分,应该作为示例呈现,以说明如何使用 API。它可能包含代码示例。
使用示例
/**
* Adds two numbers together.
*
* @remarks
* Use this function to perform example addition.
*
* @example
* Here's a simple example:
* ```
* // Prints "2":
* console.log(add(1,1));
* ```
*
* @example
* Here's an example with negative numbers:
* ```
* // Prints "0":
* console.log(add(1,-1));
* ```
*
* @param x - the first number to add
* @param y - the second number to add
* @public
*/
export function add(x: number, y: number): number {
return x + y;
}
API 文档生成器会自动对示例部分进行编号。输出可能如下所示
add() 函数将两个数字加在一起。
签名export declare function add(x: number, y: number): number;
参数返回值
参数 类型 描述 x number
要添加的第一个数字 y number
要添加的第二个数字
number
备注使用此函数执行示例加法。
示例 1这是一个简单的示例
// Prints "2":
console.log(add(1,1));示例 2这是一个使用负数的示例
// Prints "0":
console.log(add(1,-1));