Encountering TypeError in the next build when trying to call model functions for methods and/or statics from pages/api
.
The error message tends to mention either
property does not exist
orexpression is not callable
.
I have followed Mongoose Typescript recommendations.
import { Model, Schema, models, model } from 'mongoose';
import { User } from 'types/user';
interface UserModel extends Model<User> {
findAuthenticated(hash: string): Promise<User>;
getProfile(): Promise<User>;
}
const userSchema = new Schema<User, UserModel>({...});
...
export default models.User || model<User,UserModel>('User', userSchema);
Using Next.js 13 with Mongoose 6.8.2 and typescript 4.9.4.