@readonly
标准化 | 扩展 |
语法种类 | 修饰符 |
用法
此修饰符标签表明 API 项应被记录为只读,即使 TypeScript 类型系统可能另有指示。例如,假设一个类属性有一个 setter 函数,该函数总是抛出一个异常,解释该属性无法被赋值;在这种情况下,可以添加 @readonly
修饰符,以便该属性在文档中显示为只读。
示例
export class Book {
/**
* Technically property has a setter, but for documentation purposes it should
* be presented as readonly.
* @readonly
*/
public get title(): string {
return this._title;
}
public set title(value: string) {
throw new Error('This property is read-only!');
}
}