fix: remove redundant record guards

This commit is contained in:
Armin Ronacher
2026-07-05 18:55:09 +02:00
parent ee24a9ec54
commit 035ea9c856
4 changed files with 71 additions and 88 deletions
@@ -263,17 +263,11 @@ const KEYBINDING_NAME_MIGRATIONS = {
deleteSessionNoninvasive: "app.session.deleteNoninvasive",
} as const satisfies Record<string, Keybinding>;
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function isLegacyKeybindingName(key: string): key is keyof typeof KEYBINDING_NAME_MIGRATIONS {
return key in KEYBINDING_NAME_MIGRATIONS;
}
function toKeybindingsConfig(value: unknown): KeybindingsConfig {
if (!isRecord(value)) return {};
function toKeybindingsConfig(value: Record<string, unknown>): KeybindingsConfig {
const config: KeybindingsConfig = {};
for (const [key, binding] of Object.entries(value)) {
if (typeof binding === "string") {
@@ -331,7 +325,8 @@ function loadRawConfig(path: string): Record<string, unknown> | undefined {
if (!existsSync(path)) return undefined;
try {
const parsed = JSON.parse(readFileSync(path, "utf-8")) as unknown;
return isRecord(parsed) ? parsed : undefined;
if (typeof parsed !== "object" || parsed === null) return undefined;
return parsed as Record<string, unknown>;
} catch {
return undefined;
}