From f7e00e2fb33a73fc17bf3b28396cd753146eaf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Bus=C3=A0?= Date: Thu, 13 Jun 2019 12:28:30 +0200 Subject: [PATCH] Added types for dush (#36146) --- types/dush/dush-tests.ts | 9 +++++++++ types/dush/index.d.ts | 28 ++++++++++++++++++++++++++++ types/dush/tsconfig.json | 24 ++++++++++++++++++++++++ types/dush/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/dush/dush-tests.ts create mode 100644 types/dush/index.d.ts create mode 100644 types/dush/tsconfig.json create mode 100644 types/dush/tslint.json diff --git a/types/dush/dush-tests.ts b/types/dush/dush-tests.ts new file mode 100644 index 0000000000..abb4d19e6d --- /dev/null +++ b/types/dush/dush-tests.ts @@ -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 diff --git a/types/dush/index.d.ts b/types/dush/index.d.ts new file mode 100644 index 0000000000..b8dc67e4e7 --- /dev/null +++ b/types/dush/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for dush 3.0 +// Project: https://github.com/tunnckocore/dush#readme +// Definitions by: 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; diff --git a/types/dush/tsconfig.json b/types/dush/tsconfig.json new file mode 100644 index 0000000000..5266908e43 --- /dev/null +++ b/types/dush/tsconfig.json @@ -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" + ] +} diff --git a/types/dush/tslint.json b/types/dush/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dush/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }