Using JSDocs @type to document types of an object/variable

From @Marks who prompted this in the Discord server.

As JS is a dynamic language, it is difficult for code editors (like VSCode and our own code editor on playcanvas.com) to do code completion properly because types of variables aren’t always easy for the editor figure out.

In these cases, we can explicitly describe the type via JSDocs @type attribute as shown here: Use JSDoc: @type

And in doing so, will give the following effect:

4 Likes

Thanks.

Can I do this:

/** @type {boolean} */
var boolOne = false;
var boolTwo = true;

Or do I need to to do this:

/** @type {boolean} */
var boolOne = false;

/** @type {boolean} */
var boolTwo = true;

The 2nd option in this case AFAIK

1 Like

@Albertos If you want to declare multiple variables in one go, you can do this

/** @type {Array.<pc.Entity>}*/
let [entity1, entity2] = [];
2 Likes