Skip to content

Add generic type parameters to Job class hierarchy for type-safe job arguments - #107

Draft
Billos with Copilot wants to merge 2 commits into
mainfrom
copilot/research-job-classes
Draft

Add generic type parameters to Job class hierarchy for type-safe job arguments#107
Billos with Copilot wants to merge 2 commits into
mainfrom
copilot/research-job-classes

Conversation

Copilot AI commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Jobs previously lacked compile-time type safety for their run method arguments. This PR introduces generic type parameters across the job hierarchy, enabling strongly-typed job implementations without sacrificing backward compatibility.

Changes

Base infrastructure

  • Added <TArgs = unknown> generic parameter to BaseJob abstract class
  • Propagated generics through SimpleJob, TransactionJob, BudgetJob, and EndpointJob with sensible defaults matching their expected signatures

Concrete implementations

  • Updated all 11 job classes with specific type parameters reflecting their data requirements
  • Created typed interfaces for job arguments (e.g., SetBudgetJobData, UpdateBillsBudgetLimitJobArgs)
  • Eliminated unsafe type casting and replaced with compile-time generic constraints

Queue/worker compatibility

  • Updated type guards in queueArgs.ts to work with generic BaseJob<unknown>
  • No changes to runtime behavior; worker dispatcher continues to operate normally

Example

Before:

class SetBudgetForTransactionJob extends EndpointJob {
  async run(args: any) {
    const { transactionId, data } = args as JobData;
    // budget_id access is untyped
  }
}

After:

interface SetBudgetJobData { budget_id: string }
class SetBudgetForTransactionJob extends EndpointJob<{
  transactionId: string;
  data: SetBudgetJobData;
}> {
  async run({ transactionId, data }: { transactionId: string; data: SetBudgetJobData }) {
    // budget_id is now strongly typed—IDE autocomplete and type checking work
  }
}

All 77 tests passing.

Copilot AI and others added 2 commits August 29, 2026 09:54
Co-authored-by: Billos <5809662+Billos@users.noreply.github.com>
…rguments

Co-authored-by: Billos <5809662+Billos@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants