Currently, I am utilizing MongoDB and Mongoose along with TypeScript. I have encountered an issue with the following scenario:
Here is the model definition I have created:
export default conn.model<AdminInterface & Document>('Admin', adminSchema)
export interface AdminInterface {
email: string,
password: string,
role: string,
created: Date,
author: {
name: string,
bio: string,
githubUrl: string,
stackoverflowLink: string,
twitterLink: string,
image: string,
image_webp: string,
},
}
No error is thrown at this stage.
My intention is to perform a basic query like this:
import { AdminInterface } from "../model/admin"
export function getAdmin(): Promise<AdminInterface | null> {
return Admin.findOne({ role: 'admin' }, { password: 0 })
}
However, the following error is raised:
Type 'DocumentQuery<AdminInterface & Document, AdminInterface & Document, {}>' is missing the following properties from type 'AdminInterface': email, password, role, created, author
What mistake am I making? How can I specify the expected response format to the .findOne
method?