Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix define Processor typing #1368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix define Processor typing #1368

wants to merge 1 commit into from

Conversation

agix
Copy link

@agix agix commented Aug 5, 2021

Processor type used in define doesn't use generic typing.

If you try this:

import Agenda, { Job } from 'agenda'

const agenda = new Agenda()

const run = async function(job: Job<{test: string}>) {
  return Promise.resolve()
}

agenda.define('test', run)

It would raise the following typescript error :

Type '(job: Job<{ test: string; }>) => Promise<void>' is not assignable to type '(job: Job<JobAttributesData>) => Promise<void>'.

Job class use generic type but default to JobAttributesData if none is provided https://github.com/agix/agenda/blob/73184aaa8309e5e89e0cfab766b2cdd6d80e9605/lib/job/index.ts?plain=1#L127

Which is exactly the case in the current Processor definition : https://github.com/agenda/agenda/blob/master/lib/agenda/define.ts#L39-L41

@harisvsulaiman
Copy link
Member

@agix We can merge this after #1358 Where this is an explicit issue

@agix
Copy link
Author

agix commented Aug 5, 2021

Ok thank you.

@imsergiobernal
Copy link

JobAttributesData should not be generic typed because is an external resource subject to async manipulations. It should be unknown always.

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.

None yet

3 participants