• Courses
  • Tutorials
  • Practice
  • Contests
Switch to Dark Mode

TypeScript | Generics in TypeScript | Question6

Last Updated : Mar 22, 2025
Discuss
Comments

Which of the following constrains a generic type to objects with a length property?

function logLength<T extends { length: number }>(arg: T): void {
    console.log(arg.length);
}


A

The generic type T must be a number.

B

The generic type T must be a string.

C

The generic type T must have a length property.

D

The function is invalid because T cannot have constraints.

Share your thoughts in the comments