Narrowing and Discriminated Unions in TypeScript
A union type says "this value is one of several shapes". Narrowing is how TypeScript figures out which one you have inside a branch. Built-in narrowing function format(value: string | number | Date) { if (typeof value === 'string') return value.trim(); // stri...