TypeScript
TypeScript found a required property missing from the provided type
TypeScript rejected a value because it does not include one of the required properties defined by the target type.
TypeScript
TypeScript rejected a value because it does not include one of the required properties defined by the target type.
Observed message
error TS2741: Property 'X' is missing in type 'Y' but required in type 'Z'.
Why it happens
How to fix it
type Profile = { name: string; email: string };
const profile: Profile = { name: "Ada" };type Profile = { name: string; email: string };
const profile: Profile = { name: "Ada", email: "ada@example.com" };The first assignment produces TS2741 because email is required. The corrected object satisfies Profile. In a real application, use the actual email rather than a placeholder.
type Profile = { name: string; nickname: string };
const profile: Profile = { name: "Ada" };type Profile = { name: string; nickname?: string };
const profile: Profile = { name: "Ada" };
const displayName = profile.nickname ?? profile.name;Use this alternative only when nickname is genuinely optional. Reading it can produce undefined under strict null checks. With exactOptionalPropertyTypes enabled (TypeScript 4.4+), omission differs from explicitly assigning undefined unless the property type includes undefined.
Official reference
TypeScript Handbook: Object TypesRelated errors
Explore more