question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support JSDoc typedef and property

See original GitHub issue

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 typedef with 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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
tschaubcommented, Feb 12, 2018

@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:

  • it works (or could work) for both type checking and documentation
  • it doesn’t require any code that might cause issues with other tools (e.g. a rule that errors on unused variables)

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.

2reactions
phbcommented, Sep 4, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use JSDoc: @typedef
The @typedef tag is useful for documenting custom types, particularly if ... This example defines a more complex type, an object with several...
Read more >
JSDoc Reference - TypeScript: Documentation
What JSDoc does TypeScript-powered JavaScript support? ... Declared in a JSDoc @typedef tag. ... You can specify an HTML Element with DOM properties....
Read more >
How to lookup types of a typedef in JSDoc / use a property of a ...
I'm wondering how I can use the property of a typedef: given: /** * The Settings to be passed to the Class *...
Read more >
jsDoc | Add support for optional properties in @typedef with ...
jsDoc | Add support for optional properties in @typedef with @property. 2. I have next code. /** * @typedef {object} MyType * @property...
Read more >
Type safety in JavaScript with JSDoc and VSCode
Tagged with javascript, jsdoc, vscode, typescript. ... JSDoc style * @typedef {object} Rgb * @property {number} red * @property {number} ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found