You can import JSDoc types to use in your JavaScript code.
Apply a JSDoc type to a parameter to enable type checking and autocomplete.
You can skip this step if you want to use a type defined by Wix.
To define and export a type using JSDoc:
Use JSDoc tags and definitions to define a type. For example:
You can expose your type to your site's files as either a global type or a restricted type:
export {};
below your JSDoc declaration. For example:
The way that you import the JSDoc type depends on where and how the type is exposed:
Use the type without importing it. For example:
Import your type using import('<file-path.js>').<type-def-name>
directly in the JSDoc's tag type declaration. For example:
You can use Wix editor elements directly in JSDoc types without importing them. Define the JSDoc data type using $w.Element
. For example:
By default, the file for backend event handlers, events.js
, doesn't know the type of the parameter you are passing to a function.
To tell your events.js
file the parameter's type:
EventObjectName
. You can find it in the method declaration in API reference.
onBookingCreated
To add JSDoc to wix-bookings.v2
event, onBookingCreated()
:
onBookingCreated
. Find the EventObjectName
.events.js
file:/** @param {import('api-module-name').Events.BookingCreated} event */
By default, the routers.js file doesn’t support autocomplete or type checking for WixRouterRequest objects passed to router functions.
To support autocomplete or type-checking in a routers.js
file, add the following JSDoc annotation above your router functions: