Generic Interfaces and Type Aliases
Apply generics to interfaces and custom types.
Welcome
Generics are not limited to functions. Interfaces and type aliases also accept type parameters, making them reusable across many types.
Generic Interface Syntax
Add `` after the interface name to make it generic. Use T in property types and method signatures.
interface Box<T> {
value: T;
unwrap(): T;
}
const box: Box<number> = { value: 42, unwrap() { return this.value; } };All lessons in this course
- Generic Functions: Type Parameters
- Generic Interfaces and Type Aliases
- Generic Constraints with extends
- Default Type Parameters