pulsecron / pulse

The modern MongoDB-powered job scheduler library for Node.js
https://pulsecron.com
MIT License
111 stars 11 forks source link

>1.1.2 doesn't compile in TypeScript projects with `dom` library disabled #40

Closed shevchenkobn closed 5 months ago

shevchenkobn commented 5 months ago

Description

  1. Have a TypeScript project/codebase without dom type definitions (it can be done through setting tsc --lib es6 or similar).
  2. Install version after (not equal) 1.1.2 (including the latest - 1.5.1).
  3. Import anything from this package.
  4. Compile the project.

Compilation fails with the error:

node_modules/@pulsecron/pulse/dist/job/unique.d.ts:3:42 - error TS2304: Cannot find name 'Document'.

3 export type UniqueMethod<TSchema extends Document = Document> = (filter: Filter<TSchema>, options?: {
                                           ~~~~~~~~

node_modules/@pulsecron/pulse/dist/job/unique.d.ts:3:53 - error TS2304: Cannot find name 'Document'.

3 export type UniqueMethod<TSchema extends Document = Document> = (filter: Filter<TSchema>, options?: {

Code example

Compile this code

index.ts

// import {Document as MongoDocument} from 'mongodb';

// declare module '@pulsecron/pulse/dist/job/unique' {
//   type Document = MongoDocument;
// }

import {Processor} from '@pulsecron/pulse';

const p: Processor<any> = () => {};
package.json
{
  "name": "ts",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc --types node --lib es6 ./index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@pulsecron/pulse": "^1.5.1"
  },
  "devDependencies": {
    "@types/node": "^20.14.9",
    "mongodb": "^6.8.0",
    "typescript": "^5.5.2"
  }
}

Additional context

Workaround

Add the declaration augmentation file (like src\@types\pulse-fixes.d.ts):

import {Document as MongoDocument} from 'mongodb';

declare module '@pulsecron/pulse/dist/job/unique' {
  type Document = MongoDocument;
}

Or simply uncomment the commented part of the Code example.

Fix

Import Document from mongodb in @pulsecron/pulse/src/job/unique 😀 https://github.com/pulsecron/pulse/blob/dfed3ee042dd1fc63e3aff74f6bdf4032c3e561c/src/job/unique.ts#L1

And disable DOM type definitions by lib in tsconfig.

code-xhyun commented 5 months ago

@shevchenkobn I will solve these and give you an answer as soon as possible.

code-xhyun commented 5 months ago

🎉 This Issue is included in version 1.5.2 🎉

The release is available on:

npm package (@latest dist-tag) GitHub release

shevchenkobn commented 4 months ago

🎉 This Issue is included in version 1.5.2 🎉

The release is available on:

npm package (@latest dist-tag) GitHub release

Wow, thank you! You did it blazingly fast! Even I took much longer to respond 😄 I have never seen such a fast open-source issue processing!

code-xhyun commented 4 months ago

🎉 This Issue is included in version 1.5.2 🎉

The release is available on:

npm package (@latest dist-tag) GitHub release

Wow, thank you! You did it blazingly fast! Even I took much longer to respond 😄

I have never seen such a fast open-source issue processing!

@shevchenkobn I've solved this, but please check if your problem has been solved as well