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

type issue in CronJob #869

Closed
pratikkajare opened this issue Mar 15, 2024 · 7 comments
Closed

type issue in CronJob #869

pratikkajare opened this issue Mar 15, 2024 · 7 comments
Labels
support User support

Comments

@pratikkajare
Copy link

pratikkajare commented Mar 15, 2024

Description

There is an issue with this line of code:
// here is package issue with Argument of type 'CronJob<any, any> from 'cron'. This is causing an error and needs to be fixed. This can be resolved by modifying the code to ensure the correct argument type is passed.
-- this.schedulerRegistry.addCronJob(name, job);

image

Expected Behavior

.

Actual Behavior

.

Possible Fix

image

By changing the return type of the nextDates() function to DateTime | DateTime[], we can enhance the flexibility and efficiency of the code. Therefore, I recommend making this change. Thank you.
like... public nextDates(): DateTime | DateTime[];

Steps to Reproduce

just call this function using ts.

addCronJob(name: string, seconds: string) {
const job = new CronJob(${seconds} * * * * *, () => {
this.logger.warn(time (${seconds}) for job ${name} to run!);
});

this.schedulerRegistry.addCronJob(name, job); // here will get the type error
job.start();

this.logger.warn(
job ${name} added for each minute at ${seconds} seconds!,
);
}

Context

giving type error in typescript code

Your Environment

  • cron version: 3.1.6
  • NodeJS version: v20.11.0
  • Operating System and version:
  • TypeScript version (if applicable): 5.2.2
  • Link to your project (if applicable):
@sheerlox
Copy link
Collaborator

sheerlox commented Apr 7, 2024

Hey @pratikkajare, sorry for the delay. This error is usually because of a mismatch between the cron version you're using and the one your @nestjs/schedule version depends on. Could you please check if these are effectively the same?

Given the error message, I'd say you're using v3 while using an older @nestjs/schedule version which still depends on v2.

@sheerlox
Copy link
Collaborator

sheerlox commented Apr 7, 2024

Regarding the typing of nextDates in v2.4.3, even though it was unclear it nonetheless was correct: nextDates returned a DateTime when called without arguments, and an array when called with a number.

This behavior was changed in v3.0.0 by PR #519.

@freben
Copy link

freben commented Apr 8, 2024

We had to work around this too.

https://github.com/backstage/backstage/pull/24061/files

The reason is that you're depending on "@types/luxon": "~3.3.0" and we have a ^ dependency. The DateTime that you return is missing some features that were added in the 3.4 range of luxon.

You may want to release a version that has an updated type dependency range.

@sheerlox
Copy link
Collaborator

sheerlox commented Apr 8, 2024

We had to work around this too.

https://github.com/backstage/backstage/pull/24061/files

The reason is that you're depending on "@types/luxon": "~3.3.0" and we have a ^ dependency. The DateTime that you return is missing some features that were added in the 3.4 range of luxon.

You may want to release a version that has an updated type dependency range.

Thanks for the heads up, will look into that tonight!

@sheerlox
Copy link
Collaborator

sheerlox commented Apr 8, 2024

@freben just merged #831 and released v3.1.7, that should solve your issue 😃

@pratikkajare I still think your issue is related to a version mismatch, so probably stick to my first comment in the first time 😉

Let me know if there's anything more I can do!

@sheerlox sheerlox added the support User support label Apr 8, 2024
@freben
Copy link

freben commented Apr 9, 2024

Nice, thanks!

@pratikkajare
Copy link
Author

thank you so much

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

No branches or pull requests

3 participants