Types and Interfaces
What are Types and Interfaces?
// Using type
type User = {
id: string;
name: string;
age?: number; // optional
};
// Using interface
interface Product {
id: number;
title: string;
}When to Use What?
Interface
Type
Union Types
Discriminated Unions (Tagged Unions)
Function Types
Tuple Types
Mapped Types with type
Combining Types with & (Intersection)
Last updated