Skip to content

Generic constraint violation: type does not satisfy extends

Quick summary

You passed a type that does not satisfy the 'extends' constraint of the generic parameter — TypeScript rejects it.

Why this happens

  • The type argument is missing a required property that the constraint demands

  • The type argument is a supertype of the constraint instead of a subtype

  • The constraint was tightened after the call site was written, making previously valid code invalid

Minimal example

✗ Broken code
function getProperty<T extends { id: number }>(obj: T) {
  return obj.id;
}
getProperty({ name: 'test' }); // error: missing 'id' property
✓ Fixed code
function getProperty<T extends { id: number }>(obj: T) {
  return obj.id;
}
getProperty({ id: 1, name: 'test' }); // has 'id', satisfies constraint

Adding the required 'id' property to the object makes it satisfy the generic constraint, resolving the compile error.

How to diagnose

  • Read the TS error: 'Type X does not satisfy the constraint Y' and compare the two types

  • Check the generic declaration for its extends constraint and verify the type argument meets it

  • Use a type assertion if the runtime type is correct but the static type is too narrow

How to fix

  • Add the missing properties to the type argument so it satisfies the constraint

  • Widen the constraint to accept the type you need to pass, if the constraint is too restrictive

  • Use a type assertion or a wrapper type to satisfy the constraint if the runtime behavior is correct

How to prevent

  • Design generic constraints carefully and document what types are expected to satisfy them

  • When tightening constraints, update all call sites and use the compiler to find violations

Related Resources

Related Glossary

Related Lessons

  • Generics

    Learn about generic constraints.

← Back to language