TS2740Semantic Error
Since TS 3.0

Fix TS2740: Type 'X' Is Missing Properties from Type 'Y'

Learn why TypeScript throws TS2740 when an object is missing required properties, and how to add the missing fields or make them optional.

error TS2740: Type 'X' is missing the following properties from type 'Y'

What This Error Means

TypeScript error TS2740 fires when you create an object that is missing required properties from its expected type. TypeScript compares the shape of your object against the target type and finds that one or more properties are not present.

The error message is helpful — it tells you exactly which properties are missing. For example: Type '{ name: string }' is missing the following properties from type 'User': email, age.

This is different from TS2739, which reports a single missing property. TS2740 is specifically for cases where multiple properties are missing (two or more). Together, these errors enforce TypeScript's structural type system: an object must have all required properties of its declared type.

Common Causes

1. Incomplete object literals

You defined a type with several required properties but only provided some of them.

interface UserProfile {
  id: string
  name: string
  email: string
  avatarUrl: string
}
 
// ❌ Error: Type '{ id: string; name: string; }' is missing the following
// properties from type 'UserProfile': email, avatarUrl (TS2740)
const profile: UserProfile = {
  id: 'usr_123',
  name: 'Alice Johnson',
}
// ✅ Provide all required properties
const profile: UserProfile = {
  id: 'usr_123',
  name: 'Alice Johnson',
  email: 'alice@example.com',
  avatarUrl: '/avatars/alice.png',
}

2. Function return types with missing fields

When a function declares a return type, the returned object must include every required property.

interface ApiResponse {
  data: unknown
  status: number
  headers: Record<string, string>
  timestamp: Date
}
 
// ❌ Error: Type '{ data: any; status: number; }' is missing the following
// properties from type 'ApiResponse': headers, timestamp (TS2740)
function createResponse(data: unknown): ApiResponse {
  return {
    data,
    status: 200,
  }
}
// ✅ Include all required fields in the return value
function createResponse(data: unknown): ApiResponse {
  return {
    data,
    status: 200,
    headers: { 'content-type': 'application/json' },
    timestamp: new Date(),
  }
}

3. Component props missing required fields

In React, passing a component its props with missing required fields triggers TS2740.

interface CardProps {
  title: string
  description: string
  imageUrl: string
  onClick: () => void
}
 
function Card({ title, description, imageUrl, onClick }: CardProps) {
  return (
    <div onClick={onClick}>
      <img src={imageUrl} alt={title} />
      <h2>{title}</h2>
      <p>{description}</p>
    </div>
  )
}
 
// ❌ Error: Type '{ title: string; }' is missing the following
// properties from type 'CardProps': description, imageUrl, onClick (TS2740)
const element = <Card title="Welcome" />
// ✅ Either provide all props...
const element = (
  <Card
    title="Welcome"
    description="Get started with our platform"
    imageUrl="/images/welcome.png"
    onClick={() => console.log('clicked')}
  />
)
 
// ✅ ...or make some props optional in the interface
interface CardProps {
  title: string
  description?: string
  imageUrl?: string
  onClick?: () => void
}

4. Spreading a partial object into a required type

Spreading an object that only has some of the required fields does not satisfy the type.

interface DatabaseConfig {
  host: string
  port: number
  database: string
  username: string
  password: string
}
 
const baseConfig = {
  host: 'localhost',
  port: 5432,
}
 
// ❌ Error: Type '{ host: string; port: number; }' is missing the following
// properties from type 'DatabaseConfig': database, username, password (TS2740)
const config: DatabaseConfig = { ...baseConfig }
// ✅ Spread and add the missing properties
const config: DatabaseConfig = {
  ...baseConfig,
  database: 'myapp',
  username: 'admin',
  password: process.env.DB_PASSWORD ?? '',
}

How to Fix It

  1. Add the missing properties — the error message lists exactly which properties are missing. Add them to your object with appropriate values.

  2. Make properties optional — if some properties are not always needed, mark them with ? in the type definition:

interface UserProfile {
  id: string
  name: string
  email?: string    // Now optional
  avatarUrl?: string // Now optional
}
  1. Use Partial<T> — if you need an object where all properties are optional (like for update operations), wrap the type with Partial:
function updateUser(id: string, updates: Partial<UserProfile>) {
  // All properties of UserProfile are optional here
}
 
updateUser('usr_123', { name: 'New Name' }) // No error
  1. Use Pick<T, K> — if you only need specific properties from a larger type:
type UserSummary = Pick<UserProfile, 'id' | 'name'>
 
const summary: UserSummary = {
  id: 'usr_123',
  name: 'Alice',
} // No error — only id and name are required
  1. Provide default values — if properties have sensible defaults, include them in a factory function:
function createUserProfile(
  partial: Pick<UserProfile, 'id' | 'name'>
): UserProfile {
  return {
    email: '',
    avatarUrl: '/avatars/default.png',
    ...partial,
  }
}

FAQ

What causes TypeScript error TS2740?

TS2740 occurs when you assign an object to a variable, pass it to a function, or return it from a function, and the object is missing two or more required properties from the expected type. TypeScript checks the shape of your object against the target type and lists every property that is not present. This is part of TypeScript's structural type system — an object must have all required properties to be considered compatible with a type.

How do I fix the missing properties error?

You have two paths: add the missing properties to your object, or change the type definition so those properties are not required. To add properties, follow the list in the error message and provide a value for each one. To make properties optional, add ? after the property name in your interface (email?: string). For cases where you need a fully optional version of a type, use Partial<T>. For subsets, use Pick<T, 'key1' | 'key2'>.

How do I make properties optional in TypeScript?

Add a ? after the property name in the interface or type definition. For example, email?: string means the email property can be present (as a string) or absent (as undefined). You can also use the built-in utility types: Partial<T> makes all properties optional, Pick<T, K> selects a subset of properties, and Omit<T, K> removes specific properties. These utility types create new types without modifying the original.

Related Errors

Related Concepts

Share this reference

Stay Updated

Get the latest TypeScript tips, tutorials, and course updates delivered straight to your inbox.

No spam, unsubscribe at any time.