Skip to content

Commit

Permalink
Correctly type Job.dispatch (#64)
Browse files Browse the repository at this point in the history
Using an example job like this:

```typescript
export class TestJob extends Job {
	constructor (public readonly name: string) {super();}

	async handle () {
		console.log(`Hello, ${this.name}!`);
	}
}
```

You'll get type safety
  • Loading branch information
dan-gamble authored Mar 28, 2024
1 parent e34da01 commit 558f5f4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/superflare/src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ export abstract class Job {
/**
* Dispatch the job with the given arguments.
*/
static async dispatch<T extends Job>(
this: new (...arg: any[]) => T,
...args: any[]
) {
const job = new this(...args);
return job.dispatch(...args);
}
static async dispatch<T extends Job, Args extends any[]>(
this: new (...args: Args) => T,
...args: Args
) {
const job = new this(...args);

return job.dispatch(...args);
}

/**
* Convert the constructor arguments to a payload that can be sent to the queue.
Expand Down

0 comments on commit 558f5f4

Please sign in to comment.