SyntaxStudy
Sign Up

type alias

class

Creates a named type alias. Unlike interfaces, can alias primitives, unions, tuples, and mapped types.

Syntax

type AliasName = TypeDefinition;

Example

javascript
// Object type
type Point = { x: number; y: number };

// Union type
type Status = 'active' | 'inactive' | 'pending';
type ID = string | number;

// Function type
type Handler = (event: Event) => void;

// Tuple
type Coordinate = [number, number];
const pos: Coordinate = [40.7128, -74.0060];

// Intersection
type AdminUser = User & { role: string };