包括来自另一个实体的JSDoc注释(“回收”相同的注释)

时间:2019-04-04 07:16:36

标签: typescript visual-studio-code jsdoc

当我们创建一些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;
     ...
  }
}

我们如何注释类字段,以便它们回收界面字段中的注释?还是有其他方法可以对字段进行一次注释并重复使用?

感谢。

0 个答案:

没有答案