← Back to home

Daily challenge

TypeScript Discriminated Unions & Exhaustiveness Checking

Master control-flow analysis, the satisfies operator, and compile-time exhaustiveness guarantees in TypeScript.

Date: 2026-10-19Topic: typescriptDifficulty: intermediate7 min3 questions

2026-10-19typescript · intermediate · 7 minutes

0/3 answered
  1. Q1. Why is the 'satisfies' operator preferred over a colon type annotation (: Record<string, string | number>) in the configuration below?

    const palette = {
      primary: '#0f172a',
      accent: '#38bdf8',
      spacingUnit: 8,
    } satisfies Record<string, string | number>;
    
    const upper = palette.primary.toUpperCase();
  2. Q2. Which TypeScript type represents an unreachable code path and is idiomatically used in the default branch of a switch statement to enforce exhaustiveness?

    type Status = 'draft' | 'published';
    
    function label(status: Status): string {
      switch (status) {
        case 'draft': return 'Draft';
        case 'published': return 'Live';
        default: {
          const _exhaustive: never = status;
          return _exhaustive;
        }
      }
    }
  3. Q3. What is the effect of 'noUncheckedIndexedAccess: true' in tsconfig.json when indexing into a Record<string, Quiz>?