Understanding Type vs Value Matching in Pattern Matching

Hi, I use pattern matching a lot but wonder if I use it correctly. In particular, the difference between a type and a value matcher is not so clear to me. For instance, are now1 and now2 equivalent? Is one recommended over the other?

export type DefaultOption = 'zeroValues' | 'nowFragments' | 'none';
declare const defaults:DefaultOption;

const now1 = pipe(
    Match.value(defaults),
    Match.when('none', () => undefined),
    Match.when('nowFragments', () => new Date()),
    Match.when('zeroValues', () => new Date(0, 0, 0, 0, 0, 0, 0)),
    Match.exhaustive
);

const now2 = pipe(
    Match.type<DefaultOption>(),
    Match.when('none', () => undefined),
    Match.when('nowFragments', () => new Date()),
    Match.when('zeroValues', () => new Date(0, 0, 0, 0, 0, 0, 0)),
    Match.exhaustive
)(defaults);

Are all predicates usable with the two matchers? For instance, would that be correct?
const result = Match.value({ name: "John", age: 30 }).pipe(
    Match.when(
      { name: Match.string },
      (user) => `${user.name} is ${user.age} years old`
    ),
    Match.orElse(() => "Oh, not John")
  )
Was this page helpful?