RomainLanz / adonis-bull-queue

Queue system based on BullMQ for AdonisJS
MIT License
147 stars 26 forks source link

Add generic payload typing on dispatch method #1

Closed simlej closed 2 years ago

simlej commented 2 years ago

Hello 👋

I saw the note in your readme

Note: There is currently no typing support for job payloads.

You can let the user set it's own interface for the payload with a generic on the dispatch method


interface MyJobPayload {
 message: string;
}

Queue.dispatch<MyJobPayload>(
  'App/Jobs/RegisterStripeCustomer',
  { 
   message: "Hello job", // 👈 should force MyJobPayload for the payload
  },  
);

Hope it's helps

RomainLanz commented 2 years ago

Hey @simlej! 👋🏻

Thanks for your PR!

I was thinking about doing something similar to what is done in the Adonis Event system.

declare module '@ioc:Adonis/Core/Event' {
  interface EventsList {
    'new:user': { id: number; email: string }
  }
}

What do you think?

📚 https://docs.adonisjs.com/guides/events#making-events-type-safe

simlej commented 2 years ago

Oh nice !

I didn't know the ioc pattern on adonis, I have never really used adonis , I use to work with nestjs in my office.

I made another commit, let me know if this is what you thinking.

(Sorry this is my first PR)

RomainLanz commented 2 years ago

Oh wow! I wasn't expecting you to update the PR directly haha 👍🏻 Thanks! 🤗