Require a minimum shape for a type parameter.
Section: Generics
Constrain generic types
typescript
typescript
function printLength<T extends { length: number }>(value: T) {
console.log(value.length);
}Explanation
Constraints allow generic code to safely access known members.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Generics
Generic identity function
Use a type parameter for reusable function typing.
Generic array helper
Write array helpers that preserve element types.
Constrain a key parameter with `keyof`
Accept only valid property names for a given object type.