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

Types of property 'cronTime' are incompatible. #1640

Closed
2 of 4 tasks
andrey-o-first-am opened this issue Apr 15, 2024 · 2 comments
Closed
2 of 4 tasks

Types of property 'cronTime' are incompatible. #1640

andrey-o-first-am opened this issue Apr 15, 2024 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@andrey-o-first-am
Copy link

andrey-o-first-am commented Apr 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

"nest": "10.3.2"
"@nestjs/schedule": "^4.0.1"
"@types/cron": "^2.4.0"
"cron": "^3.1.7",

         const cronJob = new CronJob(
          '* * * * *',
          () => {
            this.logger.log(`${eventName} cron executed`);
          },
          null,
          false,
          'America/Los_Angeles',
        );
        
        this.schedulerRegistry.addCronJob(eventName, cronJob); // <- ts error here
        cronJob.start();
        

Error:

Argument of type 'import("/Users/aorlov/Projects/properti-api/node_modules/cron/dist/job").CronJob<null, null>' is not assignable to parameter of type 'import("/Users/aorlov/Projects/properti-api/node_modules/@nestjs/schedule/node_modules/cron/dist/job").CronJob<null, null>'.
  Types of property 'cronTime' are incompatible.
    Type 'import("/Users/aorlov/Projects/properti-api/node_modules/cron/dist/time").CronTime' is not assignable to type 'import("/Users/aorlov/Projects/properti-api/node_modules/@nestjs/schedule/node_modules/cron/dist/time").CronTime'.
      Types have separate declarations of a private property 'second'.ts(2345)
      

Minimum reproduction code

https:github.com

Steps to reproduce

 const cronJob = new CronJob(
          '* * * * *',
          () => {
            this.logger.log(`${eventName} cron executed`);
          },
          null,
          false,
          'America/Los_Angeles',
        );
        
        this.schedulerRegistry.addCronJob(eventName, cronJob);
        cronJob.start();
      

Expected behavior

The cronJob singleton should be able to be accepted by the addCronJob method as a parameter without any typescript errors.

Package version

4.0.1

NestJS version

10.3.2

cron version

3.1.3

Node.js version

v21.2.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

cron": "^3.1.7

@andrey-o-first-am andrey-o-first-am added bug Something isn't working needs triage labels Apr 15, 2024
@llllvvuu
Copy link

llllvvuu commented Apr 16, 2024

This will be fixed by #1633

NestJS practice of using exact dependencies instead of ^ makes it very susceptible to importing two different versions of a package.

For now, you can do "cron": "3.1.6" in your app (of course, your app will break again once #1633 is merged)

@kamilmysliwiec
Copy link
Member

#1633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants