Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Apr 20, 2024
1 parent bd92279 commit a22ea3d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions decorators/addToLogs.ts
Original file line number Diff line number Diff line change
@@ -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 =
<T extends new (...args: any[]) => 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>): 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], '-']
}
Expand All @@ -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), '-']
}
Expand Down

0 comments on commit a22ea3d

Please sign in to comment.