Real World Example

Feature Flags and Plan Config

Streaming apps like Netflix or Hotstar ship a config object with plans and feature flags. as const satisfies checks the shape, keeps literal names for type-safe lookups, and ?./?? handle optional user data safely.

Example

type PlanConfig = { price: number; screens: number; hd: boolean; downloads?: number };

const PLANS = {
  mobile: { price: 149, screens: 1, hd: false },
  basic: { price: 199, screens: 1, hd: true, downloads: 5 },
  premium: { price: 649, screens: 4, hd: true, downloads: 100 },
} as const satisfies Record<string, PlanConfig>;

type PlanId = keyof typeof PLANS;

type Subscriber = { name: string; plan?: PlanId; profile?: { language?: string } };

function describe(s: Subscriber): string {
  const planId: PlanId = s.plan ?? "mobile";
  const plan: PlanConfig = PLANS[planId];
  const lang = s.profile?.language ?? "English";
  return `${s.name}: ${planId} Rs.${plan.price}, ${plan.screens} screen(s), HD ${plan.hd ? "yes" : "no"}, downloads ${plan.downloads ?? 0}, ${lang}`;
}

console.log(describe({ name: "Aditi", plan: "premium", profile: { language: "Hindi" } }));
console.log(describe({ name: "Sam" }));

Output

Aditi: premium Rs.649, 4 screen(s), HD yes, downloads 100, Hindi
Sam: mobile Rs.149, 1 screen(s), HD no, downloads 0, English