重复使用打字稿接口之间的JSDOC评论
假设我有以下接口:
interface Foo {
/**
* A date string in the format `yyyy-MM-dd`
*/
archiveDate: string;
}
interface Bar {
/**
* A date string in the format `yyyy-MM-dd`
*/
publishDate: string;
}
如您所见,两个接口之间的JSDOC说明完全相同。是否有一种方法可以共享两个(可能还有更多)接口之间的描述,因此我不必多次复制/粘贴相同的描述。
Let's say I have the following interfaces:
interface Foo {
/**
* A date string in the format `yyyy-MM-dd`
*/
archiveDate: string;
}
interface Bar {
/**
* A date string in the format `yyyy-MM-dd`
*/
publishDate: string;
}
As you can see, the JSDoc descriptions are exactly the same between the two interfaces. Is there a way of sharing the descriptions between the two (and possibly many more) interfaces so I don't have to copy/paste the same description many times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以说,JSDOC评论是指此处的类型字符串,而不是属性。因此,您可以定义类型的别名并将DOC评论放在那里。
您甚至可以将格式编码为字符串字符类型:(
解决错误
表达式产生的联合类型太复杂而无法表示。(2590)
添加剩余数字作为练习reader)Then you even get errors when you don't use the format:
Playground
Arguably the JSDoc comment refers to the type string here, not the property. So you can define a type alias and put the doc comment there.
You can even encode the format as a string literal type:
(resolving the error
Expression produces a union type that is too complex to represent.(2590)
when adding the remaining digits is left as an exercise for the reader)Then you even get errors when you don't use the format:
Playground