Reusing Code Through Generic

This chapter is built from notions introduced by the previous chapters. The chapter built on top of notions by enhancing type by making them generic. Basic topics such as defining a generic class and interface are covered. Through the chapter, we move into more advanced topics such as generic constraints are part of the content. The goal of this chapter is to make your code more generic to increase the reusability of your classes, functions, and structures, to reduce the burden of duplicating code.

The content in this chapter covers the following:

  • How generic can make your code reusable
  • Accepted kinds of data structure for generic type
  • How to constrain the generic type
  • Generic and intersection
  • Default generic
  • Generic optional type
  • Generic constraints with a union type
  • Restricting string choices with keyof
  • Limiting the access to members of a generic type
  • Reducing your type creation with a mapped type
  • Generic type in TSX file
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.236.191