Generic interfaces define flexible object shapes.
Getting Started
What is TypeScript?
Basic Types
Types & Interfaces
Async TypeScript
Promises & Async/Await
TypeScript
Intermediate
FREE
Generic Interfaces
Lesson 2 of 17
Intermediate
Interactive
Syntax
TYPESCRIPT
interface ApiResponse<T> { data: T; status: number; message: string; } const res: ApiResponse<User> = { data: user, status: 200, message: "OK" };
Generic Interfaces
TYPESCRIPT
interface ApiResponse<T> { data: T; status: number; message: string; } interface User { id: number; name: string; } let response: ApiResponse<User> = { data: { id: 1, name: "Alice" }, status: 200, message: "OK" }; console.log(response.data.name);