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 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:

Get hands-on with 1400+ tech skills courses.