TypeScript Error: Object literal may only specify known properties, and '...' does not exist in type 'DeepPartial<Document>'
Try to declare your model like this:
import * as mongoose, { Schema, Document } from 'mongoose';export interface IUser extends Document { email: string; firstName: string; lastName: string;}const UserSchema: Schema = new Schema({ email: { type: String, required: true, unique: true }, firstName: { type: String, required: true }, lastName: { type: String, required: true }});// Export the model and return your IUser interfaceexport default mongoose.model<IUser>('User', UserSchema);
The problem is that req.body does not define {login, email, password} and that makes them "any". TS does not like it, if you try to add "any" to an object if a specific type is needed. You could cast req to a type which contains a body object, which contains the login, email and password. Like this:
public addNewUser (req: UserRequest, res: Response) {...}
and
interface UserRequest {body: {login: string; email: string; password: string}}