From a22ea3d279968c60e7ad27b478602a4c4b16cb51 Mon Sep 17 00:00:00 2001 From: Olivier Zalmanski <88216225+OlivierZal@users.noreply.github.com> Date: Sat, 20 Apr 2024 22:16:47 +0200 Subject: [PATCH] improve types --- decorators/addToLogs.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/decorators/addToLogs.ts b/decorators/addToLogs.ts index 3338a02..ed21482 100644 --- a/decorators/addToLogs.ts +++ b/decorators/addToLogs.ts @@ -1,27 +1,30 @@ -/* eslint-disable - @typescript-eslint/no-explicit-any, - @typescript-eslint/no-unsafe-argument -*/ import type { SimpleClass } from 'homey' const FIRST_CHAR = 0 const PARENTHESES = '()' const addToLogs = - SimpleClass>(...logs: string[]) => + < + T extends new ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...args: any[] + ) => SimpleClass, + >( + ...logs: string[] + ) => (target: T, context: ClassDecoratorContext): T => { class LogsDecorator extends target { - public error(...args: any[]): void { + public error(...args: unknown[]): void { this.#commonLog('error', ...args) } - public log(...args: any[]): void { + public log(...args: unknown[]): void { this.#commonLog('log', ...args) } - #commonLog(logType: 'error' | 'log', ...args: any[]): void { + #commonLog(logType: 'error' | 'log', ...args: unknown[]): void { super[logType]( - ...logs.flatMap((log): [any, '-'] => { + ...logs.flatMap((log): [unknown, '-'] => { if (log in this) { return [this[log as keyof this], '-'] } @@ -32,8 +35,8 @@ const addToLogs = typeof this[funcName as keyof this] !== 'function' ) { const func = this[funcName as keyof this] as ( - ...funcArgs: any[] - ) => any + ...funcArgs: unknown[] + ) => unknown if (!func.length) { return [func.call(this), '-'] }