From ec515fa8dfe64598e20aad03d027db02bd369ba5 Mon Sep 17 00:00:00 2001 From: robin labat Date: Tue, 2 Oct 2018 06:06:13 +0200 Subject: [PATCH] [cote] add error argument to responder on callback for cote package (#29159) * add error argument to responder on callback * Update index.d.ts * Update index.d.ts add line 286 to allow custom property on Event type. * Revert previous commit Revert commit [a1111453a600b7fbb3576fca3405849026a537b2](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29159/commits/a1111453a600b7fbb3576fca3405849026a537b2) * Edit send callback * Fix send callback --- types/cote/cote-tests.ts | 4 ++-- types/cote/index.d.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/types/cote/cote-tests.ts b/types/cote/cote-tests.ts index 8fd52a73a4..1851654625 100644 --- a/types/cote/cote-tests.ts +++ b/types/cote/cote-tests.ts @@ -80,10 +80,10 @@ class Readme { payload: { val: number }; } - randomResponder.on('randomRequest', (req: RandomRequest, callback: (answer: number) => void) => { + randomResponder.on('randomRequest', (req: RandomRequest, callback: (error: any, answer?: number) => void) => { const answer = Math.floor(Math.random() * 10); console.log('request', req.payload.val, 'answering with', answer); - callback(answer); + callback(null, answer); }); } diff --git a/types/cote/index.d.ts b/types/cote/index.d.ts index f6c60c54a2..4c959af76b 100644 --- a/types/cote/index.d.ts +++ b/types/cote/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for cote 0.14 +// Type definitions for cote 0.17 // Project: https://github.com/dashersw/cote#readme // Definitions by: makepost +// Labat Robin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import { EventEmitter2 } from "eventemitter2"; @@ -55,7 +56,7 @@ export class Requester extends Component { * @param event Request. * @param callback Function to execute after getting a result. */ - send(event: T, callback: (result: any) => void): void; + send(event: T, callback: (error: any, result: any) => void): void; } /** @@ -100,7 +101,7 @@ export class Responder extends Component { on( type: string | string[], listener: ( - ((event: T, callback: (result: any) => void) => void) | + ((event: T, callback: (error: any, result: any) => void) => void) | ((event: T) => Promise) ) ): this;