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..682cf01 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'); 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;