Play IT

Pattern matching

Интерактивное демо «Pattern matching».

languagesencyclopedia

Pattern matching

switch / when / match — exhaustiveness и сужение типа

switch (value) {
  case 1: return "one";
  case "ok": return "status ok";
  default: const _x: never = value;
}

Совпала ветка: case 1

Результат: one

default: never — union исчерпан