Mongoose unresolved method or function with @types/mongoose installed

If I require a mongoose model like so: `const User = require('./user')`

WebStorm can't resolved those method like, `find()` or `save()` but the code obviously works. And `const {User} = require('./user')` all the method are resolved but the app breaks. Only when I do something like this, declaring a variable first, it works:

const express = require('express');
const router = express.Router();
const argon2 = require('argon2');
const jwt = require('jsonwebtoken');

let User;
User = require('./user');

router.get('/', async function(req, res, next) {
const users = await User.find({});
});'/new', async (req, res, next) => {
const hash = await argon2.hash(req.body.password);
let user = new User({
password: hash
});'/login', async (req, res, next) => {
const email =;
const user = await User.findOne({ email: email });

if (user) {
try {
if (await argon2.verify(user.password, req.body.password)) {
const token = jwt.sign(
{ id: user._id, email: },
{ expiresIn: '1h' }
res.status(200).json({ token: token });
} else {
res.status(401).json({ message: 'Incorrect credentials' });
} catch (e) {

module.exports = router;

And I have @types for express and mongoose.
Why is that? What am I missing?

Comment actions Permalink

please vote for to be notified on any progress with it

Comment actions Permalink

I am not sure that if the same issue. I have auto completion. The method on a model just isn't resolved.


Please sign in to leave a comment.