Added types for dush (#36146)

This commit is contained in:
Andrea Busà 2019-06-13 12:28:30 +02:00 committed by Ron Buckton
parent 79f6b71c16
commit f7e00e2fb3
4 changed files with 62 additions and 0 deletions

9
types/dush/dush-tests.ts Normal file
View File

@ -0,0 +1,9 @@
import dush = require('dush');
const emitter = dush(); // $ExpectType Emitter
emitter // $ExpectType Emitter
.on('hi', place => console.log(`hello ${place}!`))
.on('hi', place => console.log(`hi ${place}, yeah!`));
emitter.emit('hi', 'world'); // $ExpectType Emitter

28
types/dush/index.d.ts vendored Normal file
View File

@ -0,0 +1,28 @@
// Type definitions for dush 3.0
// Project: https://github.com/tunnckocore/dush#readme
// Definitions by: andrycodestuffs <https://github.com/andrycodestuffs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare var dush: dush.DushStatic;
declare namespace dush {
type Handler = (...event: any[]) => void;
type WildcardHandler = (type?: string, ...event: any[]) => void;
interface DushStatic {
(): Emitter;
}
interface Emitter {
_allEvents: Array<{ [eventName: string]: Handler[] }>;
use: (plugin: (app: Emitter, options: any) => void, options?: any) => Emitter;
on(type: string, handler: Handler): Emitter;
on(type: "*", handler: WildcardHandler): Emitter;
once(type: string, handler: Handler): Emitter;
once(type: "*", handler: WildcardHandler): Emitter;
off(type: string, handler?: Handler): Emitter;
off(type: "*", handler?: WildcardHandler): Emitter;
emit(type: string, ...event: any[]): Emitter;
}
}
export = dush;

24
types/dush/tsconfig.json Normal file
View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"dush-tests.ts"
]
}

1
types/dush/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }