TS2305
TypeScriptERRORCriticalType SystemHIGH confidence
Member does not exist on type
What this means
A property or method is being accessed on an object, but it is not defined in the object's type.
Why it happens
- 1A typo when accessing a property name.
- 2Accessing a property on an object that is incorrectly typed.
- 3The object is of a union type, and the property does not exist on all types in the union.
How to reproduce
Accessing a non-existent property on a typed object.
trigger — this will error
trigger — this will error
interface User {
name: string;
id: number;
}
const user: User = { name: "Alice", id: 1 };
console.log(user.age);expected output
error TS2339: Property 'age' does not exist on type 'User'.
Fix 1
Correct the property name
WHEN The property name is misspelled.
Correct the property name
interface User {
name: string;
id: number;
}
const user: User = { name: "Alice", id: 1 };
console.log(user.id);Why this works
Using the correct property name defined in the type.
Fix 2
Add the property to the type definition
WHEN The property should be part of the object's shape.
Add the property to the type definition
interface User {
name: string;
id: number;
age: number;
}
const user: User = { name: "Alice", id: 1, age: 30 };
console.log(user.age);Why this works
Updating the type definition to include the missing property.
What not to do
✕ Use a type assertion to 'any'
This bypasses type safety and removes the benefit of using TypeScript to catch such errors.
Sources
Official documentation ↗
microsoft/TypeScript src/compiler/diagnosticMessages.json
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev