How to fix Type '{ x: string; }' is missing the following properties from type 'Y': name, age in TypeScript
This TypeScript error occurs when you assign an object that lacks required properties defined in its type or interface. TypeScript enforces that objects must include all non-optional properties.
Quick fix
Fixes Type '{ x: string; }' is missing the following properties from type 'Y': name, age
Type '{ x: string; }' is missing the following properties from type 'Y': name, age- Identify the missing properties from the error message
- Add all required properties to your object
- Mark properties as optional if they are not always required
- Use the Partial utility type for partial objects
Type '{ x: string; }' is missing the following properties from type 'Y': name, ageType '{ x: string; }' is missing the following properties from type 'Y': name, age
What this error means
This error (TS2739) occurs when TypeScript detects that an object literal or variable is missing one or more required properties that are defined in the target type, interface, or class. TypeScript performs strict type checking to ensure type safety, and when you try to assign an object to a type, all required properties must be present. The error message explicitly lists which properties are missing, helping you identify what needs to be added. This commonly happens when creating objects, passing props to components, implementing interfaces, or initializing class instances. TypeScript's excess property checking ensures that your objects conform to their declared shapes at compile time, preventing runtime errors. This is a core feature of TypeScript's structural type system - objects must have at least the properties required by their type, though they can have additional properties in most contexts.
Typical symptoms
- Compilation fails with error code TS2739
- Error message lists specific properties that are missing from the type
- Object assignment or function call is rejected by TypeScript
- IDE shows red squiggly lines under object literals or variable assignments
- React components fail to compile when required props are not passed
- Class instances cannot be created due to missing interface properties
Common causes
- Creating an object literal without all required properties defined in the type or interface
- Passing incomplete props to a React component that requires specific properties
- Initializing a variable with an empty object when the type expects properties
- Implementing an interface in a class but forgetting to include all required properties
- Assigning a partial object to a variable typed with a complete interface
- Destructuring or spreading objects that do not include all required fields
- Typos in property names that cause TypeScript to treat them as missing
How to fix "Type '{ x: string; }' is missing the following properties from type 'Y': name, age"
Read the TypeScript error carefully - it explicitly tells you which properties are missing:
Type '{ x: string; }' is missing the following properties from type 'Y': name, ageIn this example, the type Y requires name and age properties, but the object only has x. Make a note of all missing properties listed.
The most straightforward fix is to provide all required properties:
interface Person {
name: string;
age: number;
email: string;
}
// ❌ Error: missing 'email'
const user: Person = {
name: 'Alice',
age: 30
};
// ✅ Fixed: all properties provided
const user: Person = {
name: 'Alice',
age: 30,
email: 'alice@example.com'
};Ensure every property required by the type is present in your object literal.
If certain properties should not be mandatory, mark them as optional using the ? operator:
interface Person {
name: string;
age: number;
email?: string; // Now optional
phone?: string; // Now optional
}
// ✅ Valid: optional properties can be omitted
const user: Person = {
name: 'Alice',
age: 30
};This is useful when properties are truly optional in your application logic.
When you need to work with objects that may not have all properties (like during updates or initialization), use TypeScript's Partial<T> utility type:
interface Person {
name: string;
age: number;
email: string;
}
// ✅ All properties are optional
const partialUser: Partial<Person> = {
name: 'Alice'
};
// Useful for update functions
function updatePerson(id: string, updates: Partial<Person>) {
// Only the provided fields will be updated
}
updatePerson('123', { age: 31 });Other useful utility types: Required<T>, Pick<T, Keys>, and Omit<T, Keys>.
For React components, ensure you pass all required props:
interface UserCardProps {
name: string;
age: number;
email: string;
}
function UserCard({ name, age, email }: UserCardProps) {
return <div>{name} - {age}</div>;
}
// ❌ Error: missing 'email' prop
<UserCard name="Alice" age={30} />
// ✅ Fixed: all props provided
<UserCard name="Alice" age={30} email="alice@example.com" />
// Alternative: make email optional in the interface
interface UserCardProps {
name: string;
age: number;
email?: string;
}When a class implements an interface, it must include all required properties:
interface Vehicle {
make: string;
model: string;
year: number;
start(): void;
}
// ❌ Error: missing 'year' and 'start'
class Car implements Vehicle {
make: string;
model: string;
constructor(make: string, model: string) {
this.make = make;
this.model = model;
}
}
// ✅ Fixed: all interface members implemented
class Car implements Vehicle {
make: string;
model: string;
year: number;
constructor(make: string, model: string, year: number) {
this.make = make;
this.model = model;
this.year = year;
}
start(): void {
console.log('Engine started');
}
}Advanced notes
Type Assertion as a Last Resort: You can bypass this error using type assertions (as or <Type> syntax), but this defeats TypeScript's type safety and should be avoided:
const user = {} as Person; // Compiles but unsafeThis can lead to runtime errors since the object truly doesn't have the required properties. Only use this in rare cases where you're absolutely certain the properties will be added dynamically.
Excess Property Checking: TypeScript treats object literals differently from variables. Object literals undergo "excess property checking" to catch typos and mistakes. If you assign an object to a variable first, then assign that variable to a typed variable, the excess property check is bypassed.
strictNullChecks: With strictNullChecks enabled in your tsconfig.json, properties typed as non-nullable cannot be undefined or null, which can also trigger this error if you try to initialize them incompletely.
Index Signatures: For objects with dynamic properties, consider using index signatures:
interface FlexiblePerson {
name: string;
age: number;
[key: string]: string | number; // Allows additional properties
}Branded Types: For cases where you need to ensure an object is fully formed before use, consider branded types or factory functions that guarantee complete object construction.
Frequently asked questions
- What does "Type '{ x: string; }' is missing the following properties from type 'Y" mean?
- This error (TS2739) occurs when TypeScript detects that an object literal or variable is missing one or more required properties that are defined in the target type, interface, or class. TypeScript performs strict type checking to ensure type safety, and when you try to assign an object to a type, all required properties must be present. The error message explicitly lists which properties are missing, helping you identify what needs to be added.
- How do I fix "Type '{ x: string; }' is missing the following properties from type 'Y"?
- This TypeScript error occurs when you assign an object that lacks required properties defined in its type or interface. TypeScript enforces that objects must include all non-optional properties.
- What causes "Type '{ x: string; }' is missing the following properties from type 'Y"?
- Creating an object literal without all required properties defined in the type or interface Passing incomplete props to a React component that requires specific properties Initializing a variable with an empty object when the type expects properties
- Is the "Type '{ x: string; }' is missing the following properties from type 'Y" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚TypeScript Official Documentation
- 📖Typescriptlang.org - objects.html(Official Docs)
- 🐙Github.com - 29197(GitHub)
- 📝
- 📖Typescriptlang.org - utility-types.html(Official Docs)
- 🐙Github.com - 49347(GitHub)