About Type Checking and Autocomplete Using JSDoc Tags

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.

Supported IDEs

You can add and benefit from JSDoc using:

  • The editor (Wix Studio and Wix Editor).
  • The Wix IDE (Wix Studio).
  • Your local IDE (Wix Studio and Wix Editor).

You can import JSDoc only in the editor.

JSDoc tags and definitions

JSDoc tags are added to JavaScript files as comments.

Each line of JSDoc defines an item using the following format:

Copy
JSDoc tags
VariableDescription
jsdoc-tagJSDoc 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.
typeData type of the item. For example, object.
item-nameHow the item is referred to.
descriptionDescription of the item.
Optional.

Where to add JSDoc in your code

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.

JSDoc example

In the following example, we define an employee type that is then applied to a function parameter.

Copy

Type checking and autocomplete

When you apply JSDoc types to parameters, the editor can perform type checking and provide autocomplete suggestions for function arguments.

File types

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.

Important: Web modules (files with the suffix `.jsw`) support autocomplete, but not type checking.

See also

Did this help?