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: Added missing template types for returned jobs in the schedule method. #37

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

kostysh
Copy link
Contributor

@kostysh kostysh commented May 31, 2024

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.

Copy link
Contributor

@code-xhyun code-xhyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@code-xhyun code-xhyun merged commit 8011bd3 into pulsecron:main Jun 1, 2024
1 check passed
@code-xhyun
Copy link
Contributor

🎉 This PR is included in version 1.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants