Explain the concept of Type Aliasing and its limitations in TypeScript.

Instruction: Discuss what type aliases are, how they are used, and any limitations they might have.

Context: This question digs into the candidate's understanding of type aliases, their usage, and the potential drawbacks or limitations that come with their use in TypeScript.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

A type alias gives a reusable name to a type expression. It can simplify an object shape, union, tuple or generic transformation without creating a separate runtime entity.

type UserId = string; type OrderId = string; type User = { id: UserId; name: string }; type Admin = User & { permissions: string[] }; const userId: UserId = "u1"; const orderId: OrderId = userId; // same underlying string type...

Related Questions