From c4d5b01acfe0cac31f94743a57e8e619178ba563 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 25 Aug 2020 09:43:54 +1000 Subject: feat: update to TypeScript 4.0 (#6514) --- std/log/logger.ts | 34 ++++++++++++++++++---------------- std/log/mod.ts | 21 +++++++++++---------- 2 files changed, 29 insertions(+), 26 deletions(-) (limited to 'std/log') diff --git a/std/log/logger.ts b/std/log/logger.ts index d1e1d9755..c00ab78ec 100644 --- a/std/log/logger.ts +++ b/std/log/logger.ts @@ -1,12 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { - LogLevels, - getLevelByName, - getLevelName, -} from "./levels.ts"; +import { LogLevels, getLevelByName, getLevelName } from "./levels.ts"; import type { LevelName } from "./levels.ts"; import type { BaseHandler } from "./handlers.ts"; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type GenericFunction = (...args: any[]) => any; + export interface LogRecordOptions { msg: string; args: unknown[]; @@ -91,7 +90,7 @@ export class Logger { */ private _log( level: number, - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { if (this.level > level) { @@ -139,45 +138,48 @@ export class Logger { } debug(msg: () => T, ...args: unknown[]): T | undefined; - debug(msg: T extends Function ? never : T, ...args: unknown[]): T; + debug(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; debug( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { return this._log(LogLevels.DEBUG, msg, ...args); } info(msg: () => T, ...args: unknown[]): T | undefined; - info(msg: T extends Function ? never : T, ...args: unknown[]): T; + info(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; info( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { return this._log(LogLevels.INFO, msg, ...args); } warning(msg: () => T, ...args: unknown[]): T | undefined; - warning(msg: T extends Function ? never : T, ...args: unknown[]): T; + warning(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; warning( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { return this._log(LogLevels.WARNING, msg, ...args); } error(msg: () => T, ...args: unknown[]): T | undefined; - error(msg: T extends Function ? never : T, ...args: unknown[]): T; + error(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; error( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { return this._log(LogLevels.ERROR, msg, ...args); } critical(msg: () => T, ...args: unknown[]): T | undefined; - critical(msg: T extends Function ? never : T, ...args: unknown[]): T; critical( - msg: (T extends Function ? never : T) | (() => T), + msg: T extends GenericFunction ? never : T, + ...args: unknown[] + ): T; + critical( + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { return this._log(LogLevels.CRITICAL, msg, ...args); diff --git a/std/log/mod.ts b/std/log/mod.ts index 10feb04b1..512de534b 100644 --- a/std/log/mod.ts +++ b/std/log/mod.ts @@ -1,5 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { Logger } from "./logger.ts"; +import type { GenericFunction } from "./logger.ts"; import { BaseHandler, ConsoleHandler, @@ -76,11 +77,11 @@ export function getLogger(name?: string): Logger { export function debug(msg: () => T, ...args: unknown[]): T | undefined; export function debug( - msg: T extends Function ? never : T, + msg: T extends GenericFunction ? never : T, ...args: unknown[] ): T; export function debug( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { // Assist TS compiler with pass-through generic type @@ -92,11 +93,11 @@ export function debug( export function info(msg: () => T, ...args: unknown[]): T | undefined; export function info( - msg: T extends Function ? never : T, + msg: T extends GenericFunction ? never : T, ...args: unknown[] ): T; export function info( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { // Assist TS compiler with pass-through generic type @@ -108,11 +109,11 @@ export function info( export function warning(msg: () => T, ...args: unknown[]): T | undefined; export function warning( - msg: T extends Function ? never : T, + msg: T extends GenericFunction ? never : T, ...args: unknown[] ): T; export function warning( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { // Assist TS compiler with pass-through generic type @@ -124,11 +125,11 @@ export function warning( export function error(msg: () => T, ...args: unknown[]): T | undefined; export function error( - msg: T extends Function ? never : T, + msg: T extends GenericFunction ? never : T, ...args: unknown[] ): T; export function error( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { // Assist TS compiler with pass-through generic type @@ -140,11 +141,11 @@ export function error( export function critical(msg: () => T, ...args: unknown[]): T | undefined; export function critical( - msg: T extends Function ? never : T, + msg: T extends GenericFunction ? never : T, ...args: unknown[] ): T; export function critical( - msg: (T extends Function ? never : T) | (() => T), + msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { // Assist TS compiler with pass-through generic type -- cgit v1.2.3