TypeScript support

How to get autocompletion in your IDE via TypeScript?

Install the webxdc-types node package via npm and follow the instructions in its README.

Alternatively, copy webxdc.d.ts into your source dir and follow the instructions below.

How to use webxdc types?

Start by importing the file.

In TypeScript:

import type { Webxdc } from './webxdc.d.ts'

In JavaScript:

 * @typedef {import('./webxdc').Webxdc} Webxdc

This works in VS Code nicely together with the //@ts-check comment on top of your source file.

If you want you can also type your own functions using JSDoc comments.

If you don't use VS Code you can still make use of the type checking with the TypeScript compiler:

npm i -g typescript # -g stands for global installation
tsc --noEmit --allowJs --lib es2015,dom *.js

How to add your own application update payload type?

If you have a type for your state update payloads, replace the any in Webxdc<any> with your own payload type:

declare global {
  interface Window {
    webxdc: Webxdc<any>;