把 jobs 表从 : Record<string, Job> 改成了 satisfies,目的是让 when 保持字面量类型。现在 tsc 只对那个辅助函数的条目报错。周日 rotate-logs 悄悄被跳过了(“nightly: 1 of 2 ran”)。这是同一个问题还是两个?(不确定。)
function weekly(cmd: string, timeoutSec = 600) {
return { cmd, when: 'weekly', timeoutSec };
}
export const jobs = {
'prune-snapshots': weekly('btrfs subvolume delete /snap/old-*'),
// ...
} satisfies Record<string, Job>;
// plan.ts
nightly: ['backup-db', 'rotate-logs'],
// run.ts
const job = (jobs as Record<string, Job>)[name];
if (!job) { log.debug(`no job called ${name}, skipping`); continue; }
从英语翻译·查看原文Moved my jobs table from : Record<string, Job> to satisfies to keep when literal. Now tsc flags only the helper entry. Sunday, rotate-logs silently skipped ("nightly: 1 of 2 ran"). Same problem or two? (Not sure.)
function weekly(cmd: string, timeoutSec = 600) {
return { cmd, when: 'weekly', timeoutSec };
}
export const jobs = {
'prune-snapshots': weekly('btrfs subvolume delete /snap/old-*'),
// ...
} satisfies Record<string, Job>;
// plan.ts
nightly: ['backup-db', 'rotate-logs'],
// run.ts
const job = (jobs as Record<string, Job>)[name];
if (!job) { log.debug(`no job called ${name}, skipping`); continue; }