@sealed
タグ タイプ: 修飾子
TSDoc の標準化: 拡張
@sealed
修飾子は、C# の sealed
キーワードまたは Java の final
キーワードと同様のセマンティクスを備えています。クラスまたはクラスのメンバーにのみ適用されます。
クラス全体に適用すると、@sealed
修飾子は、そのクラスが子クラスによって拡張されてはならないことを示します。
メンバーに適用すると、@sealed
修飾子は、そのメンバーが子クラスの対応するメンバーによってオーバーライド (再定義) されないことを示します。@sealed
がメンバーに適用される場合は必ず、@override
修飾子も一緒に使用する必要があります。
@sealed
修飾子は、生成されたドキュメントに表示されます。
API Extractor は現時点では @sealed
修飾子が正しく使用されているかどうかを検証しません。(これは将来的に実装される可能性があります。)
使用例
この例では、@sealed
は Button
クラス全体に適用されています
/** @public */
export class Component {
. . .
}
/** @public @sealed */
export class Button extends Component {
. . .
}
/** @public */
export class FancyButton extends Button { // <-- NOT ALLOWED: THE CLASS IS SEALED
. . .
}
この例では、@sealed
はメンバー Button.componentType
に適用されています
/** @public */
export enum ComponentType {
Control,
Service
}
/** @public */
export abstract class Component {
/** The type of component */
public abstract get componentType(): ComponentType;
/**
* Draws the control on the screen
* @virtual
*/
public render(): void {
. . .
}
}
/** @public */
export class Button extends Component {
/**
* {@inheritDoc Component.componentType}
* @override @sealed
*/
public get componentType(): ComponentType {
return ComponentType.Control;
}
/**
* {@inheritDoc Control.render}
* @override
*/
public render(): void {
. . .
}
}
/** @public */
export class FancyButton extends Button {
/** @override */
public get componentType(): ComponentType { // <-- NOT ALLOWED: THE MEMBER IS SEALED
return ComponentType.Service;
}
/**
* {@inheritDoc Button.render}
* @override
*/
public render(): void { // <-- OKAY
. . .
}
}