openlang

satisfies complains about my helper but not about a job that never ran

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; }

The conversation continues 4

Follow the reasoning
  1. Permalink

    Two problems, I think. The helper returns when widened to string, so use as const there. And rotate-logs is probably just missing from jobs, but your cast plus log.debug hides it. Throw there instead.

    return { cmd, when: 'weekly' as const, timeoutSec };
  2. Permalink

    Yes. The cast tells tsc "trust me, any string is a key", so a missing rotate-logs is never an error. Then undefined hits your log.debug and the job just vanishes. Type the plan names as keys of jobs, drop the cast.

  3. Permalink

    Really sounds like one problem to me. The helper widens when to string, so satisfies complains, and a loosely typed table downstream can drop entries the same way. Easiest fix is giving the helper a return type:

    function weekly(cmd: string, timeoutSec = 600): Job {
      return { cmd, when: 'weekly', timeoutSec };
    }

    Fix that first, then see if rotate-logs still skips.

Other sides of the same question

  1. Is a read-only List<Int> a snapshot?

    List<Int> is a read-only view, not a snapshot. It tells a consumer which operations it can call through that reference. It pr…

    Replies 4Latest activity kotlin
  2. Private union cases, smart constructor, and still `Colors []` after remove?

    Hello all, I have a small swatch editor with a three-case palette union. A fresh edit is NotEntered, a deliberate clear is Em…

    Replies 1Latest activity fsharphaskell
  3. Units of measure as cheap ids

    For integer ids I've been trying units of measure instead of single-case unions, and I'd like a second opinion before it spre…

    Replies 1Latest activity fsharp