UNPKG

1.51 kBTypeScriptView Raw
1import { ExtendedDevice } from './device';
2import * as usb from './bindings';
3interface EventListeners<T> {
4 newListener: keyof T;
5 removeListener: keyof T;
6}
7interface DeviceIds {
8 idVendor: number;
9 idProduct: number;
10}
11declare module './bindings' {
12 interface Device extends ExtendedDevice {
13 }
14 interface DeviceEvents extends EventListeners<DeviceEvents> {
15 attach: Device;
16 detach: Device;
17 attachIds: DeviceIds;
18 detachIds: DeviceIds;
19 }
20 function addListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
21 function removeListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
22 function on<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
23 function off<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
24 function once<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
25 function listeners<K extends keyof DeviceEvents>(event: K): ((arg: DeviceEvents[K]) => void)[];
26 function rawListeners<K extends keyof DeviceEvents>(event: K): ((arg: DeviceEvents[K]) => void)[];
27 function removeAllListeners<K extends keyof DeviceEvents>(event?: K): void;
28 function emit<K extends keyof DeviceEvents>(event: K, arg: DeviceEvents[K]): boolean;
29 function listenerCount<K extends keyof DeviceEvents>(event: K): number;
30}
31export = usb;