From 9faaa89c157520ae5e7ba93f6b8dcc41fa3afe28 Mon Sep 17 00:00:00 2001 From: Michael Mifsud Date: Thu, 7 Mar 2019 09:46:54 +1100 Subject: [PATCH] Fix node-dogstatsd constructor type definition As per the documentation the `socket` argument to the constructor is an optional Socket type not a string type. Using a string would result in a fatal error. --- types/node-dogstatsd/index.d.ts | 7 ++++++- types/node-dogstatsd/node-dogstatsd-tests.ts | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/types/node-dogstatsd/index.d.ts b/types/node-dogstatsd/index.d.ts index 8e818f7cb6..9f3c56dff9 100644 --- a/types/node-dogstatsd/index.d.ts +++ b/types/node-dogstatsd/index.d.ts @@ -4,7 +4,10 @@ // Michael Mifsud // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + declare module "node-dogstatsd" { + import * as dgram from 'dgram'; export interface StatsDOptions { global_tags?: string[]; @@ -25,7 +28,9 @@ declare module "node-dogstatsd" { } export class StatsD implements StatsDClient { - constructor(host: string, port?: number, socket?: string, options?: StatsDOptions); + public socket: dgram.Socket + + constructor(host: string, port?: number, socket?: dgram.Socket, options?: StatsDOptions); timing(stat: string, time: number, sample_rate?: number, tags?: string[]): void; diff --git a/types/node-dogstatsd/node-dogstatsd-tests.ts b/types/node-dogstatsd/node-dogstatsd-tests.ts index 072c5b168e..949ed73eac 100644 --- a/types/node-dogstatsd/node-dogstatsd-tests.ts +++ b/types/node-dogstatsd/node-dogstatsd-tests.ts @@ -1,12 +1,14 @@ +import * as dgram from 'dgram'; import * as datadog from 'node-dogstatsd'; function test_statsd_client() { // can create client with defaults let client = new datadog.StatsD('localhost'); let options: datadog.StatsDOptions = { global_tags: ['environment:definitely_typed']}; + const socket: dgram.Socket = dgram.createSocket('udp4'); // can create client with all params - client = new datadog.StatsD('localhost', 8125, null, options); + client = new datadog.StatsD('localhost', 8125, socket, options); let key: string = 'key'; let timeValue: number = 99;