MCPcopy
hub / github.com/gvergnaud/ts-pattern / f2

Function f2

tests/select.test.ts:378–391  ·  view source on GitHub ↗
(input: Input)

Source from the content-addressed store, hash-verified

376
377 // select with an object that's a union by union
378 const f2 = (input: Input) =>
379 match(input)
380 .with({ value: P.select({ type: P.union('a', 'b') }) }, (x) => {
381 type t = Expect<
382 Equal<
383 typeof x,
384 { type: 'a'; v: string } | { type: 'b'; v: number }
385 >
386 >;
387
388 return x.v;
389 })
390 .with({ value: { type: 'c' } }, () => 'c')
391 .exhaustive();
392
393 expect(f({ value: { type: 'a', v: 'hello' } })).toEqual('hello');
394 expect(f2({ value: { type: 'a', v: 'hello' } })).toEqual('hello');

Callers 1

select.test.tsFile · 0.70

Calls 4

matchFunction · 0.90
exhaustiveMethod · 0.80
withMethod · 0.80
selectMethod · 0.80

Tested by

no test coverage detected