Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS2339: Property 'email' does not exist on type 'Object'

Tags:

angular

People also ask

How do you fix property does not exist on type?

The "Property does not exist on type '{}'" error occurs when we try to access or set 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. Copied!

What is error TS2339?

Conclusion. 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.

Does not exist in type 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 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.


Replace (data) with (data : any) on 3rd line.


Property 'hostname' does not exist on type 'Object'.

I'm using Vue and typescript, error occurred on debug when trying to console.log this.dropdownItems[0].hostname after loading some data in. The error for me looks to be a typescript type check on the declaration of the variable:

dropdownItems: Array<Object> = []

should have been:

dropdownItems: any[] = []

Derived from: https://www.reddit.com/r/ionic/comments/9cxc79/property_courses_does_not_exist_on_type_object/


The Most upvoted answer is not great because it defeats the whole purpose of Typescript also mentioned by @Alex Lomia

Solution for this are -

  1. To fix this, create an interface that describes your schema and extends mongoose.Document: check this similar question here - similar question

  2. Use Javascript instead of TypeScript , if someone is using NestJS in the backend is most likely to run into this error so if you don't want to go through the process of making interfaces and DTO's use javascript , also with javascript the built file will be smaller too .


or better practice to use interfaces. you may declare the interface:

export interface DataI {

 email: string;
 ...
 constructor(...){this.email = email .....}

and then use it as type


This same error occurred in my Nodejs Typescript project -

Code -

app.post('/form-submit', (req, res) => {
   const errors = {};
   if (...condition) {
      errors.email = ['Email is not valid.'];
   }
});

Error -

Property 'email' does not exist on type '{}'.ts(2339)

Solution (add :any and the error resolve) -

const errors:any = {};