Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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] }); 
like image 247
alik Avatar asked Dec 23 '15 20:12

alik


People also ask

Does not exist on type Typeof?

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.

Does not exist on TypeScript?

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.

Does not exist on type unknown TS 2339?

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; };

Does not exist on type never?

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.


1 Answers

You should create an instance of this class to be able to access it, like this:

var userValidators : IUserValidators = new UserValidators(); userValidators.EmailValidator(ctrl); 
like image 120
gilamran Avatar answered Oct 02 '22 12:10

gilamran