From 5e26c4f0ff9993f236e519558a4401533a902e65 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Thu, 2 Jul 2026 11:31:06 +0200 Subject: [PATCH 1/3] fix: improve type checking for OptionalLoggerImpl Use the `this` type and not the interface because the implementation has private fields. --- src/logger.ts | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 9bb84ab..e89df67 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -11,19 +11,11 @@ export interface OptionalLogger< Info extends unknown[] = unknown[], Debug extends unknown[] = unknown[], > { - error?: - | ((this: OptionalLogger, ...args: Error) => void) - | undefined; - info?: - | ((this: OptionalLogger, ...args: Info) => void) - | undefined; - warn?: - | ((this: OptionalLogger, ...args: Warn) => void) - | undefined; - debug?: - | ((this: OptionalLogger, ...args: Debug) => void) - | undefined; - flush?(this: OptionalLogger): Promise; + error?: ((this: this, ...args: Error) => void) | undefined; + info?: ((this: this, ...args: Info) => void) | undefined; + warn?: ((this: this, ...args: Warn) => void) | undefined; + debug?: ((this: this, ...args: Debug) => void) | undefined; + flush?(this: this): Promise; } /** @@ -90,21 +82,13 @@ export class OptionalLoggerImpl< Info extends unknown[] = unknown[], Debug extends unknown[] = unknown[], > implements OptionalLogger { - readonly debug?: - | ((this: OptionalLogger, ...args: Debug) => void) - | undefined = undefined; - readonly info?: - | ((this: OptionalLogger, ...args: Info) => void) - | undefined = undefined; - readonly warn?: - | ((this: OptionalLogger, ...args: Warn) => void) - | undefined = undefined; - readonly error?: - | ((this: OptionalLogger, ...args: Error) => void) - | undefined = undefined; - readonly flush: ( - this: OptionalLogger, - ) => Promise; + readonly debug?: ((this: this, ...args: Debug) => void) | undefined = + undefined; + readonly info?: ((this: this, ...args: Info) => void) | undefined = undefined; + readonly warn?: ((this: this, ...args: Warn) => void) | undefined = undefined; + readonly error?: ((this: this, ...args: Error) => void) | undefined = + undefined; + readonly flush: (this: this) => Promise; readonly #logSink: LogSink; readonly #context: Context | undefined; From 135e27eaf50e2eaaebc5263f74d558169bdd30cd Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Thu, 2 Jul 2026 11:34:36 +0200 Subject: [PATCH 2/3] chore: Do nbot skip test for type checking (#45) --- package.json | 1 + src/logger.test.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 678add9..7aa80a7 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "test": "vitest run src/", "test:watch": "vitest src/", + "fmt": "oxfmt src/", "format": "oxfmt src/", "check-format": "oxfmt --check src/", "lint": "eslint src/", diff --git a/src/logger.test.ts b/src/logger.test.ts index d718f80..6bfec92 100644 --- a/src/logger.test.ts +++ b/src/logger.test.ts @@ -412,14 +412,17 @@ function testNormalizeError(stringifiedError: string) { }); } -test.skip('type checking', () => { +test('type checking', () => { expect(true).toBe(true); const lc = new OptionalLoggerImpl(consoleLogSink, 'debug', {foo: 'bar'}); const {debug} = lc; - // @ts-expect-error Should not allow extracted method. - debug?.('a'); + const f = () => { + // @ts-expect-error Should not allow extracted method. + debug?.('a'); + }; + expect(f).toThrowError() // OK debug?.call(lc, 'a'); From a63094e8e54878565786ad4186efa778ae963150 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Thu, 2 Jul 2026 11:35:47 +0200 Subject: [PATCH 3/3] chore: fmt --- src/logger.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logger.test.ts b/src/logger.test.ts index 6bfec92..682cf01 100644 --- a/src/logger.test.ts +++ b/src/logger.test.ts @@ -422,7 +422,7 @@ test('type checking', () => { // @ts-expect-error Should not allow extracted method. debug?.('a'); }; - expect(f).toThrowError() + expect(f).toThrowError(); // OK debug?.call(lc, 'a');