2 / 2
Mar 24

I have a next.js app that connects to a mongoDB and after upgrading Typescript to the latest version the code I use to get a user from my database no longer works. There is a typescript error on the findOne method.

The typescript error reads: This expression is not callable. Each member of the union type… has signatures, but none of those signatures are compatible with each other.

The code is: const user = await User.findOne({email})

Any suggestions?

1 year later

It’s late ig, but perhaps would help someone!

you need to use the type interface from your model in your route file

import { Model } from 'mongoose'; import UserModel, { UserType } from '@/models/User'; // Adjust the import path const User = UserModel as Model<UserType>; const user = await User.findOne({ email });