Seeking Pattern Matching Solution for Union Type in TypeScript

Hey all!
I have an issue I'm trying to solve, hoping someone can help. I have a union type without a common field and I'm trying to use pattern matching on it without modifying the type. Simplified example:
type Foobar =
  | {
      foo: 'blah'
    }
  | {
      bar: 'bla blah'
    }
const thing: Foobar = generateThing()
Match.value(thing).pipe(
  Match.keyExists('foo'), () => doStuffs()),
  Match.exhaustive
)

I haven't found a function yet along the lines of keyExists though. Is there one? Or a comparable approach I can use here?
Was this page helpful?