Merge pull request #28056 from nju33/nanoevents

Add type definitions for nanoevents
This commit is contained in:
Benjamin Lichtman
2018-08-16 21:12:17 -07:00
committed by GitHub
5 changed files with 52 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for nanoevents 1.0
// Project: https://github.com/ai/nanoevents#readme
// Definitions by: nju33 <https://github.com/nju33>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare function unbind(): void;
declare class NanoEvents<T extends object> {
on<U extends keyof T>(name: U, callBack: (arg: T[U]) => any): typeof unbind;
emit<U extends keyof T>(name: U, value: T[U]): void;
}
export = NanoEvents;
+8
View File
@@ -0,0 +1,8 @@
import NanoEvents = require('nanoevents');
import unbindAll = require('nanoevents/unbind-all');
const emitter = new NanoEvents<{foo: {foo: string}, bar: {bar: string}}>();
const unbind = emitter.on('foo', action => action.foo);
emitter.emit('bar', {bar: 'test'});
unbind();
unbindAll(emitter);
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"nanoevents-tests.ts",
"unbind-all.d.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+5
View File
@@ -0,0 +1,5 @@
import NanoEmitter = require('.');
declare function unbindAll(emitter: NanoEmitter<any>): void;
export = unbindAll;