Limitations of Generic Code: Interfaces and Constrained Types
Learn about the limitations of generic code and how to use interfaces to constrain the type of T and reference common properties and functions.
We'll cover the following...
We have already seen how we can constrain the type of T
in our generic code in order to limit the number of types that can be used. Another limit of generic code is
that it can only reference functions or properties of objects that are common to any type of T
.
Interfaces and constrained type
As an example of this limitation, consider the following code:
Access this course and 1400+ top-rated courses and projects.