[英]How to do Typescript JSDoc for the fields of a typed object function parameter?
Below is a Typescript function signature x and it accepts ABC as optional parameter.下面是一个 Typescript function 签名 x,它接受 ABC 作为可选参数。 If pass in ABC, a and b are the required fields.如果传入ABC,a和b为必填字段。
async x (options: ABC = {}): Promise<string>
interface ABC {
a: string
b: number
}
Should the JSDOC look like this JSDOC 应该是这样的吗
/**
* @param {ABC} [options]
* @param {string} options.a
* @param {number} options.b
* @return {Promise<string>}
*/
Or this或这个
/**
* @param {ABC} [options]
* @param {string} [options.a]
* @param {number} [options.b]
* @return {Promise<string>}
*/
Document the structure of ABC
in the JSDoc for ABC
not in the JSDoc for x
:在ABC
的 JSDoc 中记录ABC
的结构,而不是在x
的 JSDoc 中:
interface ABC {
/**
* describe `a` here
*/
a: string
/**
* describe `b` here
*/
b: number
}
/**
* @param {ABC} options
* @return {Promise<string>}
*/
async function x (options: ABC): Promise<string> {
// IOU a promise
}
If there is nothing to describe about ABC.a
or ABC.b
, the you can skip that JSDoc altogether.如果关于ABC.a
或ABC.b
没有什么可描述的,您可以完全跳过该 JSDoc。 Typescript and your Typescript IDE already know that a
is a string and b
is a number from the interface definition. Typescript 和你的 Typescript IDE 已经从接口定义中知道a
是一个字符串, b
是一个数字。 Your proposed JSDoc would be redundant even if it were correct (it is not).您提议的 JSDoc 将是多余的,即使它是正确的(它不是)。
The signature for x
in the question produces an error, so I had to guess you intent.问题中x
的签名会产生错误,所以我不得不猜测你的意图。 See my comment under the question.请参阅我在问题下的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.