Skip to content

Commit

Permalink
Use SimpleClass
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Dec 8, 2023
1 parent 315f0b0 commit 8a5ddf9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
8 changes: 5 additions & 3 deletions decorators/addToLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
@typescript-eslint/no-explicit-any,
@typescript-eslint/no-unsafe-argument
*/
import type { LogClass } from '../types'
import type { SimpleClass } from 'homey'

const addToLogs = <T extends LogClass>(...logs: string[]) =>
function actualDecorator(target: T, context: ClassDecoratorContext<T>): T {
const addToLogs = <T extends new (...args: any[]) => SimpleClass>(
...logs: string[]
) =>
function actualDecorator(target: T, context: ClassDecoratorContext): T {
class LogsDecorator extends target {
public error(...args: any[]): void {
this.commonLog('error', ...args)
Expand Down
16 changes: 3 additions & 13 deletions types.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import type { SimpleClass } from 'homey'
import type Homey from 'homey/lib/Homey'

export const loginURL = '/R2/Account/Login'

/* eslint-disable @typescript-eslint/no-explicit-any */
interface Loggable {
/* eslint-disable @typescript-eslint/method-signature-style */
error(...errorArgs: any[]): void
log(...logArgs: any[]): void
/* eslint-enable @typescript-eslint/method-signature-style */
}

export type LogClass = new (...args: any[]) => Loggable

export type HomeyClass = new (...args: any[]) => Loggable & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type HomeyClass = new (...args: any[]) => SimpleClass & {
readonly homey: Homey

readonly setWarning?: (warning: string | null) => Promise<void>
}
/* eslint-enable @typescript-eslint/no-explicit-any */

export type CapabilityValue = boolean | number | string | null

Expand Down

0 comments on commit 8a5ddf9

Please sign in to comment.