Need Assistance?

support@tutorialshub.in

Generics (Reusable Type-Safe Code)

Generic Constraints (extends & keyof)

ADVERTISEMENT
TypeScript Free Lesson
5 min read
ADVERTISEMENT

Sometimes a generic function needs to guarantee that T has certain properties (like length or id). Use T extends { id: number } to constrain it, and K extends keyof T to ensure a key actually exists on an object!

ADVERTISEMENT
Hi, I'm Tuby! Here to help you