pulsecron / pulse

The modern MongoDB-powered job scheduler library for Node.js
https://pulsecron.com
MIT License
90 stars 4 forks source link

fix: Added missing template types for returned jobs in the schedule method. #37

Closed kostysh closed 2 months ago

kostysh commented 2 months ago

This PR should fix the following typing problem:

import { Job, JobAttributesData, Pulse } from '@pulsecron/pulse';

interface CustomJobData extends JobAttributesData {
  myOption: string;
}

const jobCreationHelper = async <T extends CustomJobData = CustomJobData>(
  queue: Pulse,
  name: string,
  data: T,
): Promise<Job<T>> => {
  const job = await queue.schedule<T>('in 5 seconds', name, data);
  return job; // <-- Type 'JobAttributesData' is missing the following properties from type 'CustomJobData': myOption (2322)
};

This typing issue appears because returned Job instances are not properly typed using T from the template type. See:

I have refactored typing in the /src/pulse/schedule.ts to fix the issue. Tests are passing.

code-xhyun commented 2 months ago

:tada: This PR is included in version 1.5.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: