I was creating a custom schema type with mongoose and typescript with express as backend but I'm getting the following error
import mongoose from 'mongoose';
class Email extends mongoose.SchemaType {
constructor(key, options) {
super(key, options, 'Email');
}
cast(val) {
if (typeof val === 'string' && !val.match(/^.+@.+$/)) {
throw new Error('Email is invalid');
}
return val;
}
}
// Don't forget to add `Email` to the type registry
mongoose.Schema.Types.Email = Email;
Is there anything I'm missing here or is it like that we need to give reference to this file?