TS2339: Property does not exist on type
Fix TypeScript error TS2339 'Property does not exist on type'. Learn to type objects correctly, use type assertions, and narrow types with guards.
What Does This Error Mean?
TypeScript error TS2339 'Property does not exist on type' means you are trying to access a property that is not defined in the type or interface of the object. TypeScript checks property access at compile time to prevent runtime errors from accessing undefined properties.
Common Causes
The property truly does not exist on the object type
The property exists at runtime but is not declared in the type definition
The object is typed too broadly (e.g., {} or object instead of a specific interface)
Accessing a property on an array when TypeScript does not know the element type
Using a string key to access an object without an index signature
TypeScript does not know the type has been narrowed (needs a type guard)
How to Fix It
Define the missing property in the interface
Add the property to the type or interface definition.
interface User {
id: number
name: string
}
// ❌ Property email does not exist on type User
console.log(user.email)
// ✅ Add it to the interface
interface User {
id: number
name: string
email: string // Added
}Use optional properties
Mark properties as optional with ? when they may not always be present.
interface Config {
apiUrl: string
timeout?: number // Optional
retries?: number // Optional
}
const config: Config = { apiUrl: "https://api.example.com" } // ✅ No timeout required
// Access with optional chaining
const timeout = config.timeout ?? 5000 // Default if undefinedAdd an index signature for dynamic properties
Use an index signature when objects have dynamic string keys.
// For objects with dynamic keys
interface Dictionary {
[key: string]: string | number
}
const dict: Dictionary = {}
dict["anyKey"] = "anyValue" // ✅ Allowed
// Or use Record utility type
const dict: Record<string, string | number> = {}
dict["key"] = 42 // ✅Use type assertions for known properties
Use 'as' to tell TypeScript the type when you know more than the compiler.
// When you know the property exists at runtime
const data: unknown = JSON.parse(response)
// ❌ Property name does not exist on unknown
console.log(data.name)
// ✅ Type assertion
const user = data as { name: string; email: string }
console.log(user.name)Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
TS2304: Cannot find name
Fix TypeScript error TS2304 'Cannot find name'. Learn how to declare types, install type definitions, and configure tsconfig.json properly.
TS18048: 'x' is possibly 'undefined'
Fix TypeScript error TS18048 'is possibly undefined'. Learn to use optional chaining, nullish coalescing, and strict null checks correctly.
TS7016: Could not find a declaration file for module
Fix TypeScript error TS7016 'Could not find a declaration file for module'. Learn to install @types, create custom .d.ts files, and configure typeRoots.
TS2683: this implicitly has type any
Fix TypeScript error TS2683 'this implicitly has type any'. Learn how to type this in callbacks, use arrow functions, and configure noImplicitThis.
Frequently Asked Questions
What is the difference between interface and type?
Both can define object shapes. Interfaces can be extended (merged) and are preferred for public API shapes. Types are more flexible — they can represent unions, intersections, and primitives. Use interface for objects, type for everything else.
How do I make a property conditionally present?
Use optional properties (?) when a property may be undefined. Use union types with undefined: `prop: string | undefined`. Use discriminated unions when the shape varies significantly: `type Result = { status: 'success'; data: T } | { status: 'error'; message: string }`.