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.
Examples
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'.
How to fix it
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.
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);Related errors
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