I'm getting an error that I can only fix with adding any
as the return value.
export const dbConnections: any = {};
export const connectDb: Promise<void> = async () => {
if (dbConnections.isConnected) {
return;
}
try {
const db = await mongoose.connect(config.get('mongoURI'), {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
});
dbConnections.isConnected = db.connections[0].readyState;
} catch (err) {
createError('Error caught connecting to db!', err);
}
};
This throws an error,
export const connectDb: Promise<void> = async () => {
^^^^^^^^^^^^^
Type '() => Promise<void>' is missing the following properties
from type 'Promise<void>': then, catch, [Symbol.toStringTag], finally
If I do any
instead of Promise<void>
, then the error disappears, but that's obviously not how I'm trying to go about this. How can I fix this lint error?
Issue is in function declaration. You need to give the return type as
Promise<void>
.