Generic Interfaces - FP Perspective
This lesson talks about generic interfaces from the perspective of Functional Programming.
We'll cover the following
Overview
Unlike OOP, objects don’t have behavior in Functional Programming. Interfaces are used not to enumerate methods of an object, but to describe the shape of the data contained by the object.
In this context, generic interfaces are used to describe a data shape when you don’t know or care about the exact type of some properties of the interface. It often makes sense when the data types contain some value.
You can find an example of such an interface below. It represents a form field that could be part of some dynamic form implementation. We want to store certain information about a form field while we don’t care about the type of data stored in that field. That’s why we introduced the generic type parameter T
.
interface FormField<T> {
value?: T;
defaultValue: T;
isValid: boolean;
}
Get hands-on with 1400+ tech skills courses.