当我们创建一些Typescript类时,我们通常还会创建“选项”接口,然后在构造函数中将其用作参数,并使用接口参数在类中复制和设置字段。我相信这是相当普遍的模式。我们想评论(JSDoc)所有可能的选项。
目前,我们在Interface
字段和Class
字段上使用相同的注释,因为它们实际上表示相同的内容。但这不是干的。但是,我们不希望Class
扩展Interface
,因为Class
中的实际字段类型可能与Interface
中的类型不同。
export interface Interface
{
/** some comment */
foo?: number[] | string[];
/** some comment */
bar?: string;
}
export class Class
{
/** some comment - same as in Interface */
foo?: ko.ObservableArray<number|string>;
/** some comment - same as in Interface */
bar?: string;
constructor(options: Interface)
{
this.foo = ko.observableArray(options.foo);
this.bar = options.bar;
...
}
}
我们如何注释类字段,以便它们回收界面字段中的注释?还是有其他方法可以对字段进行一次注释并重复使用?
感谢。