Socket
Book a DemoInstallSign in
Socket

urbit-api-ts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urbit-api-ts

A library for urbit API interaction

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Urbit Typescript bindings

Through the magic of typescript, urbit-api-ts maintains a map from marks to interfaces. It is however the developer's job to keep these updated. The general form of adding a mark is as follows.

// Anywhere in your project
export type Action = 'increment' | 'decrement';
export interface Update {
  count: number;
}


// Maps the Action interface to the 'ts-demo-action' mark
declare module 'urbit-api-ts/lib/marks' {
   interface Marks {
     'ts-demo-action': Action;
     'ts-demo-update': Update;
   }
}

This will then ensure that subscriptions and pokes have correct type inference

// Somewhere in the root component
const { bind, poke } = useUrbitApi(window.ship, onUpdate);

// type checks correctly
poke('ts-demo', 'ts-demo-action', 'increment')

// fails to type check
poke('ts-demo', 'ts-demo-value', 'increment');

// Elsewhere,
const onUpdate: UpdateHandler = ({ application, mark, value }) => {
  switch(mark) {
    case 'ts-demo-update':
      //  typechecks correctly
      const { count } = value;
      console.log(value);
    case 'ts-demo-action':
      // does not typecheck
      const { count } = value;
      console.log(value);
  }
}

FAQs

Package last updated on 28 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts