From 58234af1f6c8b6b11dc27ee84b91cccb0c9845c6 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Fri, 21 Jan 2022 10:50:55 -0800 Subject: [PATCH] Make typings match code better Fixes v6.4.0 regressions. There is an npm script `npm run typings` which actually failed before this commit. This seems to have been a combination of incorrect typings (a mandatory argument to `getLevel` that should be optional, the idea that for custom appenders `configure` should return an intermediate "generator" function before the appender function itself) as well as mistakes in the test file (which had an appender module which had one level of function nesting too few). Specifically, for the `configure` function on appenders, I believe there should be two levels of function: an outer function taking one-time configuration, and an inner function taking an individual log messages. The typings file wanted there to be three layers, and the test file wanted there to be one layer. Fixes #1155. --- types/log4js.d.ts | 9 ++------- types/test.ts | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/types/log4js.d.ts b/types/log4js.d.ts index 7d651c2c..ec26cc1e 100644 --- a/types/log4js.d.ts +++ b/types/log4js.d.ts @@ -263,14 +263,9 @@ export interface CustomAppender { } export interface AppenderModule { - configure: (config: Config, layouts: LayoutsParam) => AppenderGenerator; + configure: (config: Config, layouts: LayoutsParam) => AppenderFunction; } -export type AppenderGenerator = ( - layout: LayoutFunction, - timezoneOffset?: string -) => AppenderFunction; - export type AppenderFunction = (loggingEvent: LoggingEvent) => void; // TODO: Actually add types here... @@ -321,7 +316,7 @@ export interface Levels { FATAL: Level; OFF: Level; levels: Level[]; - getLevel(level: Level | string, defaultLevel: Level): Level; + getLevel(level: Level | string, defaultLevel?: Level): Level; addLevels(customLevels: object): void; } diff --git a/types/test.ts b/types/test.ts index a2f0fafc..b0c8d4ed 100644 --- a/types/test.ts +++ b/types/test.ts @@ -133,7 +133,7 @@ log4js.connectLogger(logger2, { //support for passing in an appender module log4js.configure({ - appenders: { thing: { type: { configure: () => {} }}}, + appenders: { thing: { type: { configure: () => () => {} }}}, categories: { default: { appenders: ['thing'], level: 'debug'}} });