With auto fix
I would like to disallow optional parameters notation with question mark character ?.
Disallow this:
/**
* @param {string?} foo Optional parameter.
*/
and this:
/**
* @param {?string} foo Optional parameter.
*/
In favor of this (auto fixed):
/**
* @param {string} [foo] Optional parameter.
*/
Actually both {string?} and {?string} cannot be disallowed and leads to inconstancy when writing optional parameter notation.
Also I'm not sure about the {string} [foo] notation, is this really the "official" notation to use when writing optional parameters?
I think so 馃 https://jsdoc.app/tags-param.html#optional-parameters-and-default-values
An optional parameter (using JSDoc syntax)
/** * @param {string} [somebody] - Somebody's name. */ function sayHello(somebody) { if (!somebody) { somebody = 'John Doe'; } alert('Hello ' + somebody); }
I believe you are confusing _optional_ and _nullable_ types. ?string is nullable and essentially an equivalent of (string|null) both in vanilla and GCC.
@param {?string} foo is a perfectly valid tag which means function parameter foo is mandatory and could be either string or null.
Optional parameter would be either @param {string=} foo or @param {string} [foo] and roughly equivalent of @param {string|undefined} foo. ECMAScript Default Parameters are fine too.
Oh yeah right, thank you!
And is there a way to disallow _nullable_ types? I'm pretty sure my team doesn't have any ?string nullable use-case 馃し鈥嶁檪
Most helpful comment
I believe you are confusing _optional_ and _nullable_ types.
?stringis nullable and essentially an equivalent of(string|null)both in vanilla and GCC.@param {?string} foois a perfectly valid tag which means function parameterfoois mandatory and could be eitherstringornull.Optional parameter would be either
@param {string=} fooor@param {string} [foo]and roughly equivalent of@param {string|undefined} foo. ECMAScript Default Parameters are fine too.