TypeScript | Generics in TypeScript | Question6

Last Updated :
Discuss
Comments

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

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


The generic type T must be a number.

The generic type T must be a string.

The generic type T must have a length property.

The function is invalid because T cannot have constraints.

Share your thoughts in the comments