import { match } from 'ts-pattern';
type Shape =
| { type: 'circle'; radius: number }
| { type: 'square'; side: number };
const shape: Shape = { type: 'circle', radius: 10 };
const area = match(shape)
.with({ type: 'circle' }, shape => Math.PI * shape.radius ** 2)
.with({ type: 'square' }, shape => shape.side ** 2)
.exhaustive();
console.log(area); // Outputs the area of the circle