type Data =
| {
id: "one";
oneValue: number;
}
| {
id: "two";
twoValue: string;
};
const discriminateValue = match
// .in allows you to specify the input TypeScript allows for your matcher
.in<Data>()
// .at allows you to specify a key at which your input will be matched
.at("id")
.match({
one: (o) => `${o.oneValue}!`,
two: (o) => o.twoValue.length,
default: "assert",
});
type Data =
| {
id: "one";
oneValue: number;
}
| {
id: "two";
twoValue: string;
};
const discriminateValue = match
// .in allows you to specify the input TypeScript allows for your matcher
.in<Data>()
// .at allows you to specify a key at which your input will be matched
.at("id")
.match({
one: (o) => `${o.oneValue}!`,
two: (o) => o.twoValue.length,
default: "assert",
});