From aa7a4241f81fcd09a5927008ba351efec0a33134 Mon Sep 17 00:00:00 2001 From: yonas Date: Fri, 19 Mar 2021 10:19:22 +0300 Subject: [PATCH] typed level type --- index.d.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 027379c39..1a967cf5e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -50,20 +50,23 @@ declare namespace winston { done(info?: any): boolean; } - type LogCallback = (error?: any, level?: string, message?: string, meta?: any) => void; + type level = "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly"; + + type LogCallback = (error?: any, level?: level, message?: string, meta?: any) => void; + interface LogEntry { - level: string; + level: level; message: string; [optionName: string]: any; } interface LogMethod { - (level: string, message: string, callback: LogCallback): Logger; - (level: string, message: string, meta: any, callback: LogCallback): Logger; - (level: string, message: string, ...meta: any[]): Logger; + (level: level, message: string, callback: LogCallback): Logger; + (level: level, message: string, meta: any, callback: LogCallback): Logger; + (level: level, message: string, ...meta: any[]): Logger; (entry: LogEntry): Logger; - (level: string, message: any): Logger; + (level: level, message: any): Logger; } interface LeveledLogMethod { @@ -78,7 +81,7 @@ declare namespace winston { levels?: Config.AbstractConfigSetLevels; silent?: boolean; format?: logform.Format; - level?: string; + level?: level; exitOnError?: Function | boolean; defaultMeta?: any; transports?: Transport[] | Transport; @@ -90,7 +93,7 @@ declare namespace winston { silent: boolean; format: logform.Format; levels: Config.AbstractConfigSetLevels; - level: string; + level: level; transports: Transport[]; exceptions: ExceptionHandler; profilers: object; @@ -133,7 +136,7 @@ declare namespace winston { child(options: Object): Logger; - isLevelEnabled(level: string): boolean; + isLevelEnabled(level: level): boolean; isErrorEnabled(): boolean; isWarnEnabled(): boolean; isInfoEnabled(): boolean; @@ -184,7 +187,7 @@ declare namespace winston { let profile: (id: string | number) => Logger; let configure: (options: LoggerOptions) => void; let child: (options: Object) => Logger; - let level: string; + let level: level; let exceptions: ExceptionHandler; let exitOnError: Function | boolean; // let default: object;