fix: resolve all TypeScript type errors across codebase for Deno strict mode
Comprehensive type safety improvements across all CLI handlers and daemon: **Error handling type fixes:** - Add 'error instanceof Error' checks before accessing error.message throughout - Fix all error/retryError/stdError/upsError type assertions - Replace direct error.message with proper type guards **Switch case improvements:** - Wrap case block declarations in braces to satisfy deno-lint - Fix no-case-declarations warnings in CLI command handlers **Null/undefined safety:** - Add checks for config.snmp and config.thresholds before access - Fix IUpsStatus lastStatusChange to handle undefined with default value - Add proper null checks in legacy configuration paths **Type annotations:** - Add explicit type annotations to lambda parameters (groupId, updateAvailable, etc.) - Add TUpsModel type cast for 'cyberpower' default - Import and use INupstConfig type where needed **Parameter type fixes:** - Fix implicit 'any' type errors in array callbacks - Add type annotations to filter/find/map parameters Files modified: - ts/cli.ts: config.snmp/thresholds null checks, unused error variable fixes - ts/cli/group-handler.ts: 4 error.message fixes + 2 parameter type annotations - ts/cli/service-handler.ts: 3 error.message fixes - ts/cli/ups-handler.ts: 5 error.message fixes + config checks + TUpsModel import - ts/daemon.ts: 8 error.message fixes + IUpsStatus lastStatusChange fix + updateAvailable type - ts/nupst.ts: 1 error.message fix - ts/systemd.ts: 5 error.message fixes + parameter type annotation All tests passing (3/3 SNMP tests + 10/10 logger tests) Type check: ✓ No errors
This commit is contained in:
@@ -78,7 +78,7 @@ export class GroupHandler {
|
||||
|
||||
logger.logBoxEnd();
|
||||
} catch (error) {
|
||||
logger.error(`Failed to list UPS groups: ${error.message}`);
|
||||
logger.error(`Failed to list UPS groups: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ export class GroupHandler {
|
||||
rl.close();
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Add group error: ${error.message}`);
|
||||
logger.error(`Add group error: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ export class GroupHandler {
|
||||
rl.close();
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Edit group error: ${error.message}`);
|
||||
logger.error(`Edit group error: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ export class GroupHandler {
|
||||
// Check if service is running and restart it if needed
|
||||
this.nupst.getUpsHandler().restartServiceIfRunning();
|
||||
} catch (error) {
|
||||
logger.error(`Failed to delete group: ${error.message}`);
|
||||
logger.error(`Failed to delete group: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ export class GroupHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
const group = config.groups.find(g => g.id === groupId);
|
||||
const group = config.groups.find((g: { id: string }) => g.id === groupId);
|
||||
if (!group) {
|
||||
logger.error(`Group with ID "${groupId}" not found.`);
|
||||
return;
|
||||
@@ -493,7 +493,7 @@ export class GroupHandler {
|
||||
|
||||
// Show current assignments
|
||||
logger.log(`\nUPS devices in group "${group.name}" (${group.id}):`);
|
||||
const upsInGroup = config.upsDevices.filter(ups => ups.groups && ups.groups.includes(groupId));
|
||||
const upsInGroup = config.upsDevices.filter((ups: { groups?: string[] }) => ups.groups && ups.groups.includes(groupId));
|
||||
if (upsInGroup.length === 0) {
|
||||
logger.log('- None');
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user