npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webxdc-types

v1.0.1

Published

TypeScript type definitions for webxdc

Downloads

449

Readme

Types for webxdc

When you develop a webxdc app, you use the webxdc API to communicate with other instances of the same webxdc application.

The API is available on window.webxdc.

When you develop your webxdc app in TypeScript, it's handy to have proper types for this API. This library provides those types for you.

Why use this?

  • you want better autocomplete in your IDE (js and ts)
  • you want to see docuemntation on hover in your IDE (js and ts)
  • you need types for typescript typechecking

Usage

You can install this using:

npm install -D webxdc-types

You should have a type that describes your webxdc payload structure in use by your application:

type Payload = {
  label: string;
  value: number;
};

Once you have a Payload type, you can declare the type of window.webxdc in your application:

import { WebXdc } from "webxdc-types";

declare global {
  interface Window {
    webxdc: WebXdc<Payload>;
  }
}

(write this in a file that is picked up by the typescript compiler, paths like src/types.d.ts or src/global.d.ts should work)

Now window.webxdc should be fully typed.

Use this if you just want completions for the api, but not for the status update payloads, they will get the any type with this method.

import "webxdc-types/global";
// or
/// <reference types="webxdc-types/global" />

Now window.webxdc should be typed.

If your IDE supports it (vscode and it's forks do), you can add //@ts-check to the top of your javascript file to enable typescript type checking for it.

you can then type variables like this

//@ts-check

/** @type {number} documentation of the value */
const my_var = 8;

You can use this to import the webxdc types when you need them to type your functions:

/**
 * @typedef {any} MyPayload
 * @typedef {import('webxdc-types').XDCFile} XDCFile
 * @typedef {import('webxdc-types').ReceivedStatusUpdate<MyPayload>} ReceivedStatusUpdate
 * @typedef {import('webxdc-types').SendingStatusUpdate<MyPayload>} SendingStatusUpdate
 * @typedef {import('webxdc-types').Webxdc<MyPayload>} Webxdc
 */
// note that this does not set `window.webxdc` for you follow the steps below for that.

Without typed payloads

If you just want the api and not want to type your payloads you can import the types for window.webxdc like this:

/** @typedef {import('webxdc-types/global')} */

With typed payloads

For this you need to create a mytypes.d.ts file declaring your payload type:

import { WebXdc } from "webxdc-types";

// do your own payload type here
type Payload = {
  label: string;
  value: number;
};

declare global {
  interface Window {
    webxdc: WebXdc<Payload>;
  }
}

Then import this file like this:

/** @typedef {import('./my_types')} */

Copy global.d.ts and webxdc.d.ts files into your project and use one of the methods above, adjusting the import path acordingly.

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

You can also combine the two files if you have basic knowledge of typescript.