Property 'Email' does not exist on type 'typeof Types'

44 views
Skip to first unread message

Juhil Somaiya

unread,
May 5, 2021, 12:43:30 AM5/5/21
to Mongoose Node.JS ODM
I was creating a custom schema type with mongoose and typescript with express as backend but I'm getting the following error
::  Property 'Email' does not exist on type 'typeof Types'


Here's my code to create a custom schema

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?
Reply all
Reply to author
Forward
0 new messages