Generic Interfaces and Types
Interfaces and aliases can take type parameters too.
Example
interface Box<T> { value: T }
const b: Box<number> = { value: 1 };
type Pair<A, B> = [A, B];
const p: Pair<string, number> = ["a", 1];
console.log(b, p);Result
{
value: 1,
} [ "a", 1 ]Exercise
Type parameter list.
interface Box { v: T }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.