简体   繁体   English

`function(* =)`在JSDoc风格的代码注释中意味着什么?

[英]What does `function(*=)` imply in a JSDoc-style code comment?

I'm writing some code comments using JSDoc style, and want to know what *= implies in @returns {function(*=): *} , which is generated by WebStorm. 我正在使用JSDoc样式编写一些代码注释,并想知道由@returns {function(*=): *} *=暗示,这是由WebStorm生成的。

I have tried to search the JSDoc wiki and usejsdoc.org but with no result. 我试图搜索JSDoc wiki和usejsdoc.org但没有结果。

Below is my code: 以下是我的代码:

/**
 * Get record data listener generator.
 * @param {Function} createProps
 * @returns {function(*=): *}        // ** generated by webstorm **
 */
export function getRecordCustomDataListener(createProps) {
  return (callback) => onRecordCustomData({ createRecordData: createProps })(callback); // `onRecordCustomData` has not default argument
}

I want to know what *= implies in @returns {function(*=): *} . 我想知道@returns {function(*=): *} *=含义。

See edit at the bottom!! 请参见底部的编辑!!

Testing it in WebStorm with a small snippet seems to indicate that *= means a parameter is not optional and can be of any type where * indicates that the parameter is of any type and optional. 使用一个小片段在WebStorm中测试它似乎表明*=表示参数不是可选的,可以是任何类型,其中*表示参数是任何类型和可选的。 See the following example with generated jsdoc from WebStorm: 请参阅以下示例,其中包含WebStorm生成的jsdoc:

/**
 *
 * @param createProps
 * @returns {function(*=, *): void}
 */
export function a(createProps) {
    return (callback, callback2) => console.log(callback);
}

As you can see we are only using the first parameter callback and leave callback2 unused. 如您所见,我们只使用第一个参数callback并且不使用callback2 Webstorm generates the proper jsdoc for that. Webstorm为此生成适当的jsdoc。

The full jsdoc for our example above in english words: Return an arrow function that takes two parameters, a **not** optional first parameter that can be of any type, and an optional second parameter that can be of any type. That function returns void 以上英语单词为例的完整jsdoc: Return an arrow function that takes two parameters, a **not** optional first parameter that can be of any type, and an optional second parameter that can be of any type. That function returns void Return an arrow function that takes two parameters, a **not** optional first parameter that can be of any type, and an optional second parameter that can be of any type. That function returns void

Docs reference: 文件参考:

http://usejsdoc.org/tags-type.html http://usejsdoc.org/tags-type.html

Optional parameter 可选参数

An optional parameter named foo. 一个名为foo的可选参数。

@param {number} [foo] @param {number} [foo]

// or: // 要么:

@param {number=} foo @param {number =} foo

An optional parameter foo with default value 1. 可选参数foo,默认值为1。

@param {number} [foo=1] @param {number} [foo = 1]


EDIT: The docs indicate that = means optional parameter but webstorm generates it with the opposite meaning. 编辑:文档表明=表示optional parameter但是webstorm以相反的含义生成它。 Either its wrongly documented or WebStorm does it wrong. 无论是错误记录还是WebStorm都错了。 I have tested it in WebStorm 2018.1 Build #WS-181.4203.535, built on March 22, 2018 我在WebStorm 2018.1 Build#WS-181.4203.535上测试了它,它建于2018年3月22日

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM