Problem Statement
Compare type vs interface with extend/merge examples and guidance on when to use each.
Explanation
Interfaces: best for public object shapes and class contracts; they extend and merge naturally. Types: best for unions, intersections, and complex transformations. Use interface when you want merging/extensibility; use type when modeling unions or composing with mapped/conditional types.
Code Solution
SolutionRead Only
interface A { x: number }
interface A { y: number } // merged
const a: A = { x: 1, y: 2 };
type B = { x: number } & { y: number };
const b: B = { x: 1, y: 2 };