I'm doing the following:
// Connect to MongoDB
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useCreateIndex: true }).then(
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
).catch((err: Error) => {
console.log('MongoDB connection error. Please make sure MongoDB is running. ' + err)
process.exit();
})
and I'm getting the following error from WebStorm TypeScript service (running TSLint manually works fine):
TS2345: Argument of type '{ useNewUrlParser: boolean; useCreateIndex: boolean; }' is not assignable to parameter of type '(err: MongoError) => void'. Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type '(err: MongoError) => void'.
This seems to be an issue with @types/mongoose
, but I've looked everywhere and I can't find where it's coming from.
Here is a workaround which does not really explain the issue:
mongoose.set('useNewUrlParser', true)
mongoose.set('useCreateIndex', true)
mongoose.connect(MONGODB_URI).then(...
Edit: mongoose 6 no longer need these options.
@types/mongoose
, because I stopped seing this issue after upgrading it 1 or 2 weeks later – Taryntaryne