From 531f8b9c147ea6c80ecbe38c654e3e8bfba152cb Mon Sep 17 00:00:00 2001 From: Ashley Abbott Date: Wed, 20 Nov 2019 14:40:00 -0500 Subject: [PATCH] Implement bunyan-format as both callable and newable (#40473) * Updating type with tslint hint and tests to be verbose Signed-off-by: Ashley Abbott * Redundant declare and required newlines Signed-off-by: Ashley Abbott --- types/bunyan-format/bunyan-format-tests.ts | 21 +++++++++++++++++++++ types/bunyan-format/index.d.ts | 17 ++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/types/bunyan-format/bunyan-format-tests.ts b/types/bunyan-format/bunyan-format-tests.ts index 6467fccc7b..89425727d5 100644 --- a/types/bunyan-format/bunyan-format-tests.ts +++ b/types/bunyan-format/bunyan-format-tests.ts @@ -1,10 +1,31 @@ +import bunyan = require('bunyan'); import BunyanFormatWritable = require('bunyan-format'); import { Writable } from 'stream'; const formatOut: Writable = new BunyanFormatWritable({ outputMode: 'short' }); +const logger1 = bunyan.createLogger({ + name: 'formatOut', + stream: formatOut, +}); + const formatOut2: NodeJS.WritableStream = new BunyanFormatWritable({ outputMode: 'bunyan', levelInString: true }); +const logger2 = bunyan.createLogger({ + name: 'formatOut2', + stream: formatOut2, +}); + const formatOut3: Writable = BunyanFormatWritable({ outputMode: 'short' }); +const logger3 = bunyan.createLogger({ + name: 'formatOut3', + stream: formatOut3, +}); + const formatOut4: NodeJS.WritableStream = BunyanFormatWritable({ outputMode: 'bunyan', levelInString: true }); + +const logger4 = bunyan.createLogger({ + name: 'formatOut4', + stream: formatOut4, +}); diff --git a/types/bunyan-format/index.d.ts b/types/bunyan-format/index.d.ts index 13cec4d397..5ae1d347c7 100644 --- a/types/bunyan-format/index.d.ts +++ b/types/bunyan-format/index.d.ts @@ -23,14 +23,13 @@ declare namespace BunyanFormatWritable { } } -// tslint:disable-next-line no-empty-interface -interface BunyanFormatWritable extends Writable {} - -declare var BunyanFormatWritable: { - /** Creates a writable stream that formats bunyan records written to it. */ - (options: BunyanFormatWritable.Options, output?: Writable): BunyanFormatWritable; - /** Creates a writable stream that formats bunyan records written to it. */ +/** Creates a writable stream that formats bunyan records written to it. */ +interface BunyanFormatWritable extends Writable { + // tslint:disable-next-line no-misused-new new (options: BunyanFormatWritable.Options, output?: Writable): BunyanFormatWritable; -}; + (options: BunyanFormatWritable.Options, output?: Writable): BunyanFormatWritable; +} -export = BunyanFormatWritable; +declare const BunyanFormat: BunyanFormatWritable; + +export = BunyanFormat;