TypeScript '...' does not exist in typeof type ...

I have this piece of code, no matter what I try, I cannot get the following error.

Error: The property 'EmailValidator' does not exist for the type 'typeof UserValidators'.

Code:

import {EMAIL_REGEX} from '../constants'; import {Control} from 'angular2/common'; export interface IUserValidators { EmailValidator(control: Control) : Object; } export class UserValidators implements IUserValidators { EmailValidator(control: Control) : Object { if (!control.value) { return { required: true }; } else if (control.value) { if (!new RegExp(EMAIL_REGEX).test(control.value)) { return { invalid: true }; } } return {}; } } 

This is how I try to enter EmailValidator:

 this.fb.group({ email: ['', UserValidators.EmailValidator] }); 
+5
source share
1 answer

You must create an instance of this class in order to access it, for example:

 var userValidators : IUserValidators = new UserValidators(); userValidators.EmailValidator(ctrl); 
+5
source

Source: https://habr.com/ru/post/1239089/


All Articles