Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
9 changes: 6 additions & 3 deletions src/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
40 changes: 12 additions & 28 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ export interface OptionalLogger<
Info extends unknown[] = unknown[],
Debug extends unknown[] = unknown[],
> {
error?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Error) => void)
| undefined;
info?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Info) => void)
| undefined;
warn?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Warn) => void)
| undefined;
debug?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Debug) => void)
| undefined;
flush?(this: OptionalLogger<Error, Warn, Info, Debug>): Promise<void>;
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<void>;
}

/**
Expand Down Expand Up @@ -90,21 +82,13 @@ export class OptionalLoggerImpl<
Info extends unknown[] = unknown[],
Debug extends unknown[] = unknown[],
> implements OptionalLogger<Error, Warn, Info, Debug> {
readonly debug?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Debug) => void)
| undefined = undefined;
readonly info?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Info) => void)
| undefined = undefined;
readonly warn?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Warn) => void)
| undefined = undefined;
readonly error?:
| ((this: OptionalLogger<Error, Warn, Info, Debug>, ...args: Error) => void)
| undefined = undefined;
readonly flush: (
this: OptionalLogger<Error, Warn, Info, Debug>,
) => Promise<void>;
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<void>;

readonly #logSink: LogSink<Error, Warn, Info, Debug>;
readonly #context: Context | undefined;
Expand Down