TypeScript · Middle · Question 3 of 75
What does <T extends { id: string }> mean in a generic?
- ✓Correct answer: A constraint:
Tmust have at least anid: stringproperty - 2
Tinherits a class with anidfield, as withclass extends - 3
Tcan be exactly{ id: string }and nothing else
Explanation
A constraint lets you safely access item.id inside the function while keeping the full type T in the result. You can pass any object with a suitable id and other fields. Classes and inheritance have nothing to do with it.