Skip to content

Commit

Permalink
🔧 Improve type safety in utils and tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyperb1iss committed Aug 16, 2024
1 parent 21d40b1 commit 8b6dc4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/hyper-light-card.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,22 @@ export function memoize<TArgs extends unknown[], TResult>(
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);
}
Expand Down

0 comments on commit 8b6dc4d

Please sign in to comment.