Ad Space — Top Banner

TS2339

TypeScript Programming Language

Severity: Minor

What Does This Error Mean?

TypeScript error TS2339 means you are trying to access a property on an object that TypeScript does not know exists. TypeScript checks every property access against the type definition. If the property is not listed in the type, you get TS2339. This often happens with API responses, third-party data, or when TypeScript infers a narrower type than you expect. Fix it by updating the type definition, using a type assertion, or narrowing the type properly.

Affected Models

  • TypeScript 1.0 and later
  • All TypeScript versions
  • tsc compiler, ts-node, webpack, Vite, Next.js

Common Causes

  • Accessing a property that is not defined in the TypeScript interface or type for that object
  • TypeScript inferred the type as a base class that does not have the property from the derived class
  • Using an API response typed as unknown or any but then accessing properties without a type assertion
  • Typo in the property name — the property exists but the name is slightly different
  • The property was added to a JavaScript library but the @types package has not been updated yet

How to Fix It

  1. Check the property name for typos. Compare it to the type definition or documentation. TypeScript is case-sensitive.

    VS Code shows available properties with IntelliSense (Ctrl+Space). Use this to see the correct property name.

  2. If the property should exist but is not in the type, add it to your interface or type: interface MyType { newProp: string; }

    If you do not own the type (it comes from a library), see the steps below for working with external types.

  3. If you are working with a JSON API response, define an interface that matches the response shape and cast: const data = response as MyApiType;

    Alternatively, use a type guard or validation library like Zod to safely parse and type external data.

  4. If the property exists on a subtype, use a type narrowing check first: if ('myProp' in myObject) { myObject.myProp }

    The 'in' operator narrows the type inside the if block so TypeScript knows the property exists there.

  5. If you are extending a third-party type, use declaration merging or module augmentation to add the missing property to the existing type.

    In a .d.ts file: declare module 'some-library' { interface SomeType { myNewProp: string; } }

When to Call a Professional

TS2339 is a compile-time error that is almost always quick to fix. The error tells you the property name and the type it was accessed on. Check both for typos first — that solves most cases instantly.

Frequently Asked Questions

Can I just use 'any' to stop the error?

Yes, casting to any silences the error: (myObject as any).myProperty. But this defeats the purpose of TypeScript and hides real bugs. The better approach is to define the correct type. Use any only as a last resort or temporary workaround.

The property definitely exists at runtime — why does TypeScript complain?

TypeScript only knows what it can see in type definitions. If the property is added dynamically at runtime, TypeScript cannot know about it. You need to tell TypeScript about it by updating the type or using a type assertion. For fully dynamic objects, consider using Record<string, unknown> or an index signature: { [key: string]: unknown }

What is the difference between TS2339 and TS2304?

TS2304 means a whole name (variable, function, or type) cannot be found. TS2339 means the name was found, but a specific property on it does not exist in its type. TS2304 is about finding the object itself. TS2339 is about finding a property on an object you already have.