Writing an optional array parameter with Google Closure Compiler syntax
/**
* @param {string[]=} foo Description.
*/
Is returning an error
error Syntax error in type: string[]= jsdoc/valid-types
But {string[]=} looks valid 馃 the = character should not be part of the "type"
I'm using
settings : {
jsdoc : {
preferredTypes : {
"Array.<>" : "[]",
".<>" : "<>"
}
}
},
rules : {
"jsdoc/check-syntax": "off"
}
Does Closure accept it? I see at https://jsdoctypeparser.github.io/ that using (string[])= works though I don't know if that should be necessary.
If this should work, please file an issue at https://github.com/jsdoctypeparser/jsdoctypeparser , with indication of whether it works in Closure (and/or if you can find it, whether the docs make clear it is allowed).
Ok I've created an issue in the parser repo https://github.com/jsdoctypeparser/jsdoctypeparser/issues/110
PS: Note that I'm not using Closure it self, only the Closure JSDoc notation
Just saw your comment about not using Closure itself now, but if you can at least link to the docs for the optional syntax so we can clarify whether it should work without parentheses, that should be helpful. Thanks...
I think we can close and track there now instead. Thanks again!
@brettz9 I cannot find any mention of an optional notation of value[] using Closure 馃
But the real problem for me is the fix of preferredTypes: { "Array.<>" : "[]" } that converts:
/**
* @param {Array.<string>=} foo
*/
to:
/**
* @param {string[]=} foo
*/
And the fix turns out to convert an error to another error
The fix should include parenthesis for optional parameters, like so:
/**
* @param {(string[])=} foo
*/
Do you want me to open a new issue?
As you stated in the parser issue the parenthesis are unnecessary as the {string[]=} notation is perfectly explicit without any ambiguity.
As I understand when the parser issue https://github.com/jsdoctypeparser/jsdoctypeparser/issues/110 will be fixed there will be no need to wrap {string[]=} around parenthesis during fix.
Ok, closing then for now and can track there.