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.
This commit is contained in:
Michael Mifsud
2019-03-07 09:46:54 +11:00
parent 32f41ca45d
commit 9faaa89c15
2 changed files with 9 additions and 2 deletions

View File

@@ -4,7 +4,10 @@
// Michael Mifsud <https://github.com/xzyfer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;

View File

@@ -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;