Lingua-e
← Errors
JavaScript

Property does not exist on type: What It Means and How to Fix It

Error reference

Property does not exist on type

Language

JavaScript

Severity

Medium

When it happens

This TypeScript compile error (TS2339) is reported when you try to access a property that is not declared in the type of the variable.

Potential fixes

Add the missing property to the interface or type definition. If the property is optional, mark it with a question mark (email?: string). Use type assertions (as MyType) sparingly and only when you are certain of the runtime shape. Keep type definitions in sync with API responses using code generation tools.

Deep dive

This TypeScript compile error (TS2339) is reported when you try to access a property that is not declared in the type of the variable. TypeScript enforces that every property access is known at compile time, so accessing an undeclared property is an error even if it might exist at runtime.

Why it happens

  • Accessing a property that was never added to the interface or type definition.
  • A typo in the property name that does not match any declared field.
  • Accessing a property on the result of an API call typed as a generic or base type that does not include that property.
  • A library was upgraded and a property was renamed or removed in the new version.

Potential fixes

Add the missing property to the interface or type definition. If the property is optional, mark it with a question mark (email?: string). Use type assertions (as MyType) sparingly and only when you are certain of the runtime shape. Keep type definitions in sync with API responses using code generation tools.

Examples

JavaScript

Code that triggers the error

interface User {
  id: number;
  name: string;
}

const user: User = { id: 1, name: "Alice" };
console.log(user.email);

Error output

error TS2339: Property 'email' does not exist on type 'User'.

Fixed code

interface User {
  id: number;
  name: string;
  email?: string;  // add the property (optional)
}

const user: User = { id: 1, name: "Alice", email: "alice@example.com" };
console.log(user.email);

Practice in English

How would you explain a Property does not exist on type to a fellow dev? Choose the right phrase:

"I hit an error...

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free