Rush Stack商店博客活动
跳至主要内容

@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;
参数
参数类型描述
xnumber要添加的第一个数字
ynumber要添加的第二个数字
返回值

number

备注

使用此函数执行示例加法。

示例 1

这是一个简单的示例

// Prints "2":
console.log(add(1,1));
示例 2

这是一个使用负数的示例

// Prints "0":
console.log(add(1,-1));

另请参阅