Skip to content

npm/cron types do not match with Sentry.cron.instrumentNodeCron #10294

@Tethik

Description

@Tethik

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.94.1

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

I try the example given at
https://docs.sentry.io/platforms/node/crons/#cron

For my project in typescript. Using the latest versions of both cron and @sentry/node

import * as Sentry from "@sentry/node";
import { CronJob } from "cron";

const CronJobWithCheckIn = Sentry.cron.instrumentCron(
  CronJob,
  "my-cron-job"
);

However I get a Type error as the type expected by instrumentCron does not match the actual one from CronJob:

 error TS2345: Argument of type 'typeof CronJob' is not assignable to parameter of type 'typeof CronJob & CronJobConstructor'.
         Type 'typeof CronJob' is not assignable to type 'CronJobConstructor'.
           Types of property 'from' are incompatible.
             Type '<OC extends CronOnCompleteCommand | null = null, C = null>(params: CronJobParams<OC, C>) => CronJob<OC, C>' is not assignable to type '(param: CronJobParams) => CronJob'.
               Types of parameters 'params' and 'param' are incompatible.
                 Type 'CronJobParams' is not assignable to type 'CronJobParams<() => void | Promise<void>, unknown>'.
                   Type 'CronJobParams' is not assignable to type 'BaseCronJobParams<() => void | Promise<void>, unknown> & { timeZone?: undefined; utcOffset?: number | null | undefined; }'.
                     Type 'CronJobParams' is not assignable to type '{ timeZone?: undefined; utcOffset?: number | null | undefined; }'.
                       Types of property 'timeZone' are incompatible.
                         Type 'string | undefined' is not assignable to type 'undefined'.
                           Type 'string' is not assignable to type 'undefined'.

From the error description it seems CronJobConstructor.from is not correctly defined.

Expected Result

Example from the documentation should be working.

Actual Result

Does not work :(

Metadata

Metadata

Assignees

Labels

BugPackage: nodeIssues related to the Sentry Node SDK

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions