While attempting to set up a simple test file following the jest documentation, I encountered several linter errors:
https://i.sstatic.net/bAPjC.png
connection:
The type 'Promise<MongoClient> & void' is missing properties such as '{ db: (arg0: any) => any; close: () => any; }': db, closets(2739)
globalThis.MONGO_URI_:
Element implicitly has an 'any' type because type 'typeof globalThis' lacks an 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 tried setting up a global.d.ts
(following these solutions) file with the given declarations below:
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;
}
Although I initially believed this solved the globalThis.__MONGO_URI__
error, it reappeared after restarting VS Code.
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"
},