TS2344: Type 'X' does not satisfy the constraint 'Y'

Typescript·Sep 13, 2026·intermediate·
Quick answer

You're passing a type argument to a generic that doesn't satisfy the `extends` constraint the generic parameter declares. Check what the constraint actually requires (e.g. `T extends { id: string }`), and either pass a type that genuinely matches it, or loosen the constraint if it was written more narrowly than the function actually needs.

What causes this error

A generic type parameter declared with extends (like T extends { id: string }) restricts what types can be passed for T — TypeScript checks the actual type argument (explicit or inferred) against that constraint, and TS2344 means it fails the check.

The Fix

function getById<T extends { id: string }>(items: T[], id: string) {
  return items.find((item) => item.id === id);
}

interface Product {
  sku: string; // no `id` field
}

// Wrong — Product doesn't have an `id` property, so it fails the constraint
getById<Product>(products, 'p1'); // TS2344

// Fix 1 — make the type satisfy the constraint
interface Product {
  id: string;
  sku: string;
}

// Fix 2 — if the constraint is too strict for the function's real needs, loosen it
function getById<T extends { sku: string } | { id: string }>(items: T[], key: string) { /* ... */ }

Common causes / variations

  • Passing a domain type that genuinely doesn't have the shape the generic function requires
  • A constraint written more narrowly than the function's actual logic needs
  • Forgetting a required generic type argument entirely and letting TypeScript infer something incompatible

Related errors

See also: TS2589 Type instantiation excessively deep, TS2769 No overload matches this call.

Was this fix helpful?

Comments

Loading comments...

Fix: TS2344 Type does not satisfy the constraint | BugFixer | BugFixer