Learn why TypeScript throws TS2740 when an object is missing required properties, and how to add the missing fields or make them optional.
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.
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',
}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(),
}
}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
}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 ?? '',
}Add the missing properties — the error message lists exactly which properties are missing. Add them to your object with appropriate values.
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
}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 errorPick<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 requiredfunction createUserProfile(
partial: Pick<UserProfile, 'id' | 'name'>
): UserProfile {
return {
email: '',
avatarUrl: '/avatars/default.png',
...partial,
}
}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.
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'>.
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.
Get the latest TypeScript tips, tutorials, and course updates delivered straight to your inbox.