I have a method that saves an author with the .findOneAndUpdate
AuthorInterface looks like this:
export interface AuthorInterface {
name: string,
bio: string,
githubLink: string,
stackoverflowLink: string,
twitterLink: string,
image: string,
image_webp: string,
}
In this case I need to make an exception here. image and image_webp are image paths and therefore I cannot just override the values. I already used Omit to remove it out of the AuthorInterface argument.
However typescript still complains at author: { ...author } that image_webp and image fields are missing. How do I tell typescript that I don't expect image and image_webp properties to be in the argument object?
public saveAuthor(_id: mongoose.Types.ObjectId | string, author: Omit<AuthorInterface, "image" | "image_webp">): Promise<UserModelInterface | null> {
return User.findOneAndUpdate({ _id }, { author: { ...author } }, { new: true }).exec()
}