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

Function get

tests/instance-of.test.ts:13–23  ·  view source on GitHub ↗
(x: A | B)

Source from the content-addressed store, hash-verified

11describe('instanceOf', () => {
12 it('should work at the top level', () => {
13 const get = (x: A | B): string =>
14 match(x)
15 .with(P.instanceOf(A), (x) => {
16 type t = Expect<Equal<typeof x, A>>;
17 return 'instance of A';
18 })
19 .with(P.instanceOf(B), (x) => {
20 type t = Expect<Equal<typeof x, B>>;
21 return 'instance of B';
22 })
23 .exhaustive();
24
25 expect(get(new A())).toEqual('instance of A');
26 expect(get(new B())).toEqual('instance of B');

Callers 1

Calls 3

matchFunction · 0.90
exhaustiveMethod · 0.80
withMethod · 0.80

Tested by

no test coverage detected