Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us

Home/TypeScript Errors/TS2339

TS2339

Property 'X' does not exist on type 'Y'

TypeScript TS2339 fires when you try to access a property that TypeScript cannot find in the type definition of the object. The property either doesn't exist, is misspelled, or needs to be added to the type.

Why This Happens

You are accessing obj.someProperty but the type of obj doesn't declare someProperty. Common causes: typos, accessing a property only present on one member of a union type, using a JavaScript library without @types, or the object type is too narrow.

Code That Triggers TS2339

// TS2339 examples
const user = { name: "Alice", age: 30 };
console.log(user.email);
// Error: Property 'email' does not exist on type '{ name: string; age: number; }'

// Also common with union types
type Dog = { breed: string };
type Cat = { indoor: boolean };
function describePet(pet: Dog | Cat) {
  console.log(pet.breed);
  // Error: Property 'breed' does not exist on type 'Dog | Cat'
}

How to Fix TS2339

Option 1: Add the property to the type/interface

interface User {
  name: string;
  age: number;
  email?: string; // add as optional if not always present
}

Option 2: Narrow the union type first

function describePet(pet: Dog | Cat) {
  if ("breed" in pet) {
    console.log(pet.breed); // OK — TypeScript knows it's a Dog
  }
}

Option 3: Use a type assertion (when certain)

(user as any).email; // escape hatch — avoid if possible
(user as UserWithEmail).email; // better — cast to correct type

Frequently Asked Questions — TS2339

What does TS2339 mean?

TS2339 means you're accessing a property that TypeScript can't verify exists on that type. It's a safety check — TypeScript prevents you from reading properties that may not be there at runtime.

How do I fix TS2339 for a JavaScript library?

Install the @types package: npm install --save-dev @types/library-name. If no @types package exists, declare the module in a .d.ts file or use 'declare module' with the type shape.

Why does TS2339 appear on a union type?

Union types only expose properties common to all members. To access a property specific to one member, narrow the type first using 'in' checks, typeof, instanceof, or a discriminant property.

Can I suppress TS2339 with optional chaining?

No — optional chaining (obj?.prop) prevents runtime errors but doesn't fix the TypeScript error. You still need the property in the type definition. Optional chaining only handles undefined/null values.

TS2339 appears even though the property exists — why?

The type inferred for your object may not include that property. Either TypeScript inferred a narrower type, or the object was typed with an interface that doesn't declare it. Add the property to the interface or use a wider type.

Convert JavaScript to TypeScript automatically

Paste your JS code and get type-annotated TypeScript — including fixes for common type errors — in seconds.

Try the converter →

Other TypeScript Errors

From the blog

View all →