I'd love to use the compiler with JSDoc typedef and property annotations.
I know that typedef can be currently used, but it requires to define an actual JavaScript variable.
e.g.
/**
* @typedef {{
* x:number,
* y:number
* }}
*/
let Point;
According to JSDoc typedef docs it can be named within the annotiation itself => it does not require the let Point; code.
I know that it is not a big deal. Well, it is a bit, because we use the ESLint to lint our code and unused variables are considered to be an error (I am aware that I can add exception, but it's annoying).
It would be great if the compiler supported the property annotation too. Again, I know that I can use record-like annotation, but this seems to be a bit more readable.
/**
* @typedef {Object} Point
* @property {!number} x Longitude
* @property {!number} y Latitude
*/
EDIT:
I tried to compile the following typedefwith the rest of my code.
/**
* @typedef {Object} Point
* @property {number} lat
* @property {number} lon
*/
var Point;
and it seems to work. But it is not listed in the Closure annotation docs. Is the property annotation already supported?
Is the property annotation already supported?
It's not supported. See this example where property lat is not recognized.
As for the original request, we don't have plans for these additions. Having many ways to annotate the same thing can be confusing.
@dimvar - is there any chance this could be reconsidered? I agree that multiple annotation styles can be confusing, but the @typedef and @property combo feels like it is clearly better syntax for these reasons:
If this style of annotation were supported, it could be the favored style and the legacy style could be removed from the reference documentation to avoid confusion.
The Closure Compiler offers a lot of great functionality. The development experience using it could be improved if it "played well" with other tools - specifically documentation and static analysis tools.
And about type name? In case we defining type as variable in the extern file it could be name-clashed with other identifier in minified code.
Another vote to reconsider this. It's getting increasingly hard to justify following closure rules whenever someone googles jsdoc and picks the (cleaner?) syntax of @typedef + @property
If we could at least add some kind of explicit error, so that it's just just JSC_UNRECOGNIZED_TYPE_ERROR when nothing is wrong with syntax. Kinda silly:
/**
* A callback that modifies Widget state in
* response to an event or other trigger. Not
* throttled.
*
* @typedef {Function} StateGenerator
*/
Fails unless you add a dummy variable, let StateGenerator; below it.
Many thanks to @tSte for this workaround.
Most helpful comment
@dimvar - is there any chance this could be reconsidered? I agree that multiple annotation styles can be confusing, but the
@typedefand@propertycombo feels like it is clearly better syntax for these reasons:If this style of annotation were supported, it could be the favored style and the legacy style could be removed from the reference documentation to avoid confusion.
The Closure Compiler offers a lot of great functionality. The development experience using it could be improved if it "played well" with other tools - specifically documentation and static analysis tools.