So I have a Node /w Typescript REST API, I have signup method which creates a user and responses with the created users firstName, lastName, email.
The problem is I am having this typescript error that says "Type 'Document' is missing the following properties from type 'SavedUser': firstName, lastName, email".
I believe its something with adding mongoose.Document type in my SavedUser Interface, i am not sure tho, thanks for the help!
Sample Code:
interface SavedUser {
firstName: string
lastName: string
email: string
}
...
public async signUp(req: Request, res: Response): Promise<void | Response> {
const salt: string = await bcrypt.genSalt(10)
const hashedPassword: string = await bcrypt.hash(req.body.password, salt)
const user = new User({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
password: hashedPassword
})
try {
const { firstName, lastName, email }: SavedUser = await user.save()
return res.status(200).send({
firstName,
lastName,
email
})
} catch (err) {
return res.status(400).send(err)
}
}