Creating generic interfaces
In this lesson, we will learn how to create generic interfaces.
We'll cover the following...
Generic interface syntax
We can pass types into an interface that are used within its definition like we can to a function. The syntax for a generic interface is below:
interface InterfaceName<T1, T2, ...> {
...
}
The members of the interface can reference the generic types passed into it.
Generic interface example
A common use case for a generic interface is a generic form interface. This is because all forms have values, default values, validation rules, etc. but the specific fields differ from form to form.
Below is a simple generic form interface:
interface Form<T> {
values: T;
}
...