0

When I try to set up a simple test file, as per the jest documentation I get a number of linter errors:

screengrab showing errors

connection: Type 'Promise<MongoClient> & void' is missing the following properties from type '{ db: (arg0: any) => any; close: () => any; }': db, closets(2739)

globalThis.MONGO_URI_: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.ts(7017)

useNewUrlParser: No overload matches this call. Overload 1 of 4, '(url: string, callback: Callback<MongoClient>): void', gave the following error. Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'Callback<MongoClient>'....

I've tried setting up a global.d.ts (as per these solutions) file with the following declarations in:

export interface globalThis {}
declare module globalThis {
    var __MONGO_URI__: string;
    var __MONGO_DB_NAME__: string;
}

export interface global {}
declare global {
    var __MONGO_URI__: string;
    var __MONGO_DB_NAME__: string;
}

I think this solved the globalThis.__MONGO_URI__ error previously, but I've turned VS Code back on and the error has re-appeared.

package.json dependencies:

 "dependencies": {
    "cross-env": "^7.0.3",
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "node-cron": "^3.0.0",
    "snoostorm": "^1.5.2",
    "snoowrap": "^1.23.0",
    "mongodb": "^4.6.0"
  },
  "devDependencies": {
    "@babel/core": "^7.18.2",
    "@babel/preset-env": "^7.18.2",
    "@babel/preset-typescript": "^7.17.12",
    "@shelf/jest-mongodb": "^3.0.1",
    "@types/express": "^4.17.13",
    "@types/jest": "^27.5.1",
    "@types/mongodb": "^4.0.7",
    "@types/node": "^17.0.36",
    "@types/node-cron": "^3.0.1",
    "@types/request": "^2.48.8",
    "jest": "^28.1.0",
    "jest-environment-node": "^28.1.0",
    "ts-jest": "^28.0.3",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.2"
  },
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71
  • 1
    Please provide a [mvce](https://stackoverflow.com/help/minimal-reproducible-example) – Lin Du Jun 06 '22 at 08:37
  • Thanks! I've added the package.json dependencies. The file with the errors is a copy and paste from step 3, here: https://jestjs.io/docs/mongodb – JimmyTheCode Jun 06 '22 at 09:50

0 Answers0