TypeScript
Structural vs nominal typing
TypeScript uses structural typing: compatibility is based on shape, not names.
Structural typing
interface Point { x: number; y: number }
interface Coordinate { x: number; y: number }
const p: Point = { x: 10, y: 20 };
const c: Coordinate = p;Nominal typing
Nominal systems require shared declarations or inheritance.
Example
type User = { id: number };
type Admin = { id: number; role: string };
const admin: Admin = { id: 2, role: "admin" };
const anotherUser: User = admin;