TypeScript · Middle · Question 3 of 75

What does <T extends { id: string }> mean in a generic?

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.

Further reading

Problem with a question

TypeScript · Middle · question 3

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz