JSDoc is a popular markup language used to document JavaScript code, applying type checking and autocomplete as you write your code. You can use JSDoc in a Wix environment in the same way as you would in any JavaScript environment. Adding JSDoc to your custom code allows you to benefit from type checking and code autocomplete.
You can add and benefit from JSDoc using:
You can import JSDoc only in the editor.
JSDoc tags are added to JavaScript files as comments.
Each line of JSDoc defines an item using the following format:
Variable | Description |
---|---|
jsdoc-tag | JSDoc tag that defines what the item is. For example, use @typedef to define a new type, @property to define the property of an object, and @param to define a parameter. |
type | Data type of the item. For example, object . |
item-name | How the item is referred to. |
description | Description of the item. Optional. |
You can add JSDoc to Velo code as you would to any JavaScript code, by including the annotations just above the code you are documenting. However, when defining a parameter type, using the @param
tag, place the JSDoc definition directly above the function declaration.
In the following example, we define an employee
type that is then applied to a function parameter.
When you apply JSDoc types to parameters, the editor can perform type checking and provide autocomplete suggestions for function arguments.
You can add JSDoc in any JavaScript file, meaning the file's suffix is .js
. This includes JavaScript files in Velo packages, allowing anyone using your packages to use type checking and autocomplete.
You can import types defined by Wix in some specific file types.
For example, you can import backend event objects to events.js
files.