From 8b6dc4d253e55061f8cf78fd8a2f88bd04ddd68c Mon Sep 17 00:00:00 2001 From: Stefanie Jane Date: Thu, 15 Aug 2024 22:26:51 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Improve=20type=20safety=20in=20u?= =?UTF-8?q?tils=20and=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace 'any' with 'unknown' for better type safety In hyper-light-card.test.ts: - Update type assertions from 'as any' to 'as unknown' In utils.ts: - Modify log function parameters from 'any[]' to 'unknown[]' - Add explicit return type 'void' to log functions --- src/hyper-light-card.test.ts | 6 +++--- src/utils.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hyper-light-card.test.ts b/src/hyper-light-card.test.ts index a1b119e..7d3224f 100644 --- a/src/hyper-light-card.test.ts +++ b/src/hyper-light-card.test.ts @@ -21,7 +21,7 @@ describe('HyperLightCard', () => { }, }, callService: jest.fn(), // Mock the callService function - } as any; + } as unknown; // Set up the required config property card.setConfig({ entity: 'light.test_light' }); @@ -59,7 +59,7 @@ describe('HyperLightCard', () => { it('throws an error when no entity is provided', () => { expect(() => { - card.setConfig({} as any); + card.setConfig({} as unknown); }).toThrow('You need to define an entity'); }); @@ -107,7 +107,7 @@ describe('HyperLightCard', () => { }, }, callService: jest.fn(), - } as any; + } as unknown; // Set the initial internal state card['_isOn'] = true; // Light is initially on diff --git a/src/utils.ts b/src/utils.ts index a542bd0..6b169ac 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -144,22 +144,22 @@ export function memoize( const isLoggingEnabled = process.env.NODE_ENV !== 'production'; // Disable logging in production by default export const log = { - debug: (...args: any[]) => { + debug: (...args: unknown[]): void => { if (isLoggingEnabled) { console.debug(...args); } }, - log: (...args: any[]) => { + log: (...args: unknown[]): void => { if (isLoggingEnabled) { console.log(...args); } }, - warn: (...args: any[]) => { + warn: (...args: unknown[]): void => { if (isLoggingEnabled) { console.warn(...args); } }, - error: (...args: any[]) => { + error: (...args: unknown[]): void => { if (isLoggingEnabled) { console.error(...args); }