Error Encyclopedia
TS2339

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

1

The property truly does not exist on the object type

2

The property exists at runtime but is not declared in the type definition

3

The object is typed too broadly (e.g., {} or object instead of a specific interface)

4

Accessing a property on an array when TypeScript does not know the element type

5

Using a string key to access an object without an index signature

6

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 undefined

Add 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:

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 }`.