npm ts-pattern 3.2.5
v3.2.5

latest releases: 5.4.0, 5.3.1, 5.3.0...
3 years ago

Bugfixes

  • Fix a bug with exhaustiveness checking, where a case could wrongfully be considered handled even if the pattern was containing additional keys that aren't present in the input type. This can happen when making a typo when declaring your pattern for instance, as demonstrated in the issue #44 .
type Person = {
  sex: "Male" | "Female";
  age: "Adult" | "Child";
};

function summary(person: Person): string {
  return (
    match(person)
      // Typo – "agf" should be "age"
      .with({ sex: "Female", agf: "Adult" }, () => "Woman")
      .with({ sex: "Female", age: "Child" }, () => "Girl")
      .with({ sex: "Male", age: "Adult" }, () => "Man")
      .with({ sex: "Male", age: "Child" }, () => "Boy")
      // Bugfix: This pattern is no longer considered exhaustive!
      .exhaustive()
  );
}

Don't miss a new ts-pattern release

NewReleases is sending notifications on new releases.