prisma-queue icon indicating copy to clipboard operation
prisma-queue copied to clipboard

"Could not find a declaration file for module '@mgcrea/prisma-queue'."

Open sunweiyang opened this issue 3 months ago • 1 comments

I have a Node.js Prisma project that uses TypeScript. When I updated @mgcrea/prisma-queue from 1.12.0 to 1.12.1, I got the following TS error:

Could not find a declaration file for module '@mgcrea/prisma-queue'.  '/Users/****/****/node_modules/.pnpm/@m
[email protected]_@[email protected]/node_modules/@mgcrea/prisma-queue/dist/index.cjs' implicitly has an 
'any' type.

To resolve this, I had to create my own mgcrea-prisma-queue.d.ts file, but it's not ideal. Here it is, both for reference and as potential inspiration for patching?

declare module "@mgcrea/prisma-queue" {
  import { PrismaClient } from "@prisma/client";

  export interface QueueJob<TPayload = any, TResult = any> {
    id: string;
    name: string;
    payload: TPayload;
    result?: TResult;
    status: "pending" | "running" | "completed" | "failed";
    createdAt: Date;
    updatedAt: Date;
    startedAt?: Date;
    completedAt?: Date;
    failedAt?: Date;
    error?: string;
    attempts: number;
    maxAttempts: number;
  }

  export interface QueueOptions {
    name: string;
    maxAttempts?: number;
    pollInterval?: number;
    jobInterval?: number;
    backoff?: {
      type: "exponential" | "fixed";
      delay: number;
    };
  }

  export interface ScheduleOptions {
    key: string;
    cron: string;
  }

  export interface EnqueueOptions {
    key?: string;
    runAt?: Date;
    maxAttempts?: number;
  }

  export interface Queue<TPayload = any, TResult = any> {
    name: string;
    push(payload: TPayload): Promise<QueueJob<TPayload, TResult>>;
    enqueue(
      payload: TPayload,
      options?: EnqueueOptions
    ): Promise<QueueJob<TPayload, TResult>>;
    schedule(options: ScheduleOptions, payload: TPayload): Promise<void>;
    start(prismaClient?: PrismaClient): Promise<void>;
    process(
      prismaClient: PrismaClient,
      options?: { concurrency?: number }
    ): Promise<void>;
    stop(): Promise<void>;
  }

  export function createQueue<TPayload = any, TResult = any>(
    options: QueueOptions,
    handler: (
      job: QueueJob<TPayload, TResult>,
      prismaClient: PrismaClient
    ) => Promise<TResult>
  ): Queue<TPayload, TResult>;
}

sunweiyang avatar Sep 30 '25 01:09 sunweiyang

same issue, something wrong with 1.12.x version

younes200 avatar Oct 22 '25 10:10 younes200