0.3.1 • Published 4 years ago

ts-nodecg v0.3.1

Weekly downloads
80
License
MIT
Repository
github
Last release
4 years ago

ts-nodecg

CircleCI

Type your bundle with bundle specific definition like replicants and messages.

This library replaces the type definition in NodeCG core (nodecg/types/{browser,server}.d.ts). If you use this library, don't use the type definition in NodeCG core.

Install

npm i -D ts-nodecg
# or
yarn add -D ts-nodecg

TypeScript 3.5 or newer is recommended

Usage

First, define your bundle's replicant and messages.

type ReplicantMap = {
	players: Array<{name: string; twitter: string}>;
	// ...
};

type MessageMap = {
	updateFoo: {
		// optional value to send with sendMessage / value to receive from listenFor
		data: number;
		// optional value to receive from sendMessage / value to send with listenFor callback
		result: number;
		// optional error object/value sent from listenFor callback
		error: CustomError;
	};
};

For server-side (extension)

import {CreateNodecgInstance} from 'ts-nodecg/server';

type NodeCG = CreateNodecgInstance<
	'my-bundle', // name of your bundle
	BundleConfig,
	ReplicantMap,
	MessageMap
>;

export = (nodecg: NodeCG) => {
	// ...
};

For client-side (dashboard/graphics)

Define the global nodecg/NodeCG variables somewhere in the project.

import {CreateNodecgInstance, CreateNodecgConstructor} from 'ts-nodecg/browser';

declare global {
	interface Window {
		nodecg: CreateNodecgInstance<
			'my-bundle', // name of your bundle
			BundleConfig,
			ReplicantMap,
			MessageMap
		>;
		NodeCG: CreateNodecgConstructor<
			'my-bundle', // name of your bundle
			BundleConfig,
			ReplicantMap,
			MessageMap
		>;
	}
}

Exposing your bundle's definition

Coming Soon

License

MIT © Keiichiro Amemiya

0.3.1

4 years ago

0.3.0

5 years ago

0.3.0-0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1-4

5 years ago

0.0.1-3

5 years ago

0.0.1-2

5 years ago

0.0.1-1

5 years ago

0.0.1-0

5 years ago