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

@override

标签类型:修饰符

TSDoc 标准化: 扩展

@override 修饰符在语义上类似于 C# 中的 override 关键字。它只应应用于类的成员。@override 修饰符表示该成员正在覆盖(即重新定义)来自基类的相应成员。基类成员应标记为 @virtual@override

@override 修饰符将显示在生成的文档中。

API 提取器目前不验证 @override 修饰符是否被正确使用。(这可能会在将来实现。)

注意:与许多其他编程语言不同,TypeScript 支持类静态成员的继承。因此,对静态成员和实例成员使用 @virtual@override@sealed 是有效的。

用法示例

/** @public */
export class Control {
/**
* The title of the control
* @virtual
*/
public get title(): string {
return 'Control';
}

/**
* Draws the control on the screen
* @virtual
*/
public render(): void {
. . .
}
}

/** @public */
export class Button extends Control {
/**
* {@inheritDoc Control.title}
* @override
*/
public get title(): string {
return 'Button';
}

/**
* {@inheritDoc Control.render}
* @override
*/
public render(): void {
. . .
}
}

/** @public */
export class FancyButton extends Button {
/**
* {@inheritDoc Button.title}
* @override
*/
public get title(): string {
return 'Fancy Button';
}

/**
* {@inheritDoc Button.render}
* @override
*/
public render(): void {
. . .
}
}

另请参见