I have this piece of code that whatever I try, I can not get passed the following error.
Error: Property 'EmailValidator' does not exist on 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 inject the EmailValidator:
this.fb.group({ email: ['', UserValidators.EmailValidator] });
The "Property does not exist on type Object" error occurs when we try to access a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names.
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the string type. To solve the error, use an object instead of a string, or make sure you're accessing a valid built-in method on the string.
To fix the error "TS2339: Property 'x' does not exist on type 'Y'" with TypeScript, we should make sure the properties are listed in the interface that's set as the type of the object. interface Images { main: string; [key: string]: string; } const getMainImageUrl = (images: Images): string => { return images. main; };
The error "Property does not exist on type 'never'" occurs when we forget to type a state array or don't type the return value of the useRef hook. To solve the error, use a generic to explicitly type the state array or the ref value in your React application.
You should create an instance of this class to be able to access it, like this:
var userValidators : IUserValidators = new UserValidators(); userValidators.EmailValidator(ctrl);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With