npm ts-pattern 3.2.2
v3.2.2

latest releases: 5.2.0, 5.1.2, 5.1.1...
2 years ago

Fix a bug reported in issue #40, where object pattern containing a single wildcard would match any object, even if the key used by the pattern wasn't present on the input object.

type Id = { teamId: number } | { storeId: number };

const selectedId: Id = { teamId: 1 };

match<Id>(selectedId)
  .with({ storeId: __ }, () => "storeId")
  .with({ teamId: __ }, () => "teamId")
  .exhaustive()
// Now outputs "teamId" instead of "storeId"

Don't miss a new ts-pattern release

NewReleases is sending notifications on new releases.