timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.15k stars 160 forks source link

Typescript typing issue with work and batchSize #401

Closed nomocas closed 1 year ago

nomocas commented 1 year ago

Hello @timgit,

There is an issue with the typing when using boss.work with batchSize.

As the documentations say, and as the tests files show, when using batchSize in work options, we should provide a work handler that accept an array of jobs as argument.

But when doing this in TS, there is an error.

await boss.work(
    'myqueue',
    { batchSize: 3 },
    (jobs: Job<Foo>[]) => Promise.resolve() 
);
error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '(jobs: Job<Foo>[]) => Promise<void>' is not assignable to parameter of type 'WorkHandler<unknown>'.
      Types of parameters 'jobs' and 'job' are incompatible.
        Type 'Job<unknown>' is missing the following properties from type 'Job<Foo>[]': length, pop, push, concat, and 29 more.

The typing misses some overloads to handle this case.

I prepare a PR.

Cheers.