type Data =
| {
id: 1
oneValue: number
}
| {
id: 2
twoValue: string
};
const discriminateValue = type.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({
1: (o) => `${o.oneValue}!`,
2: (o) => o.twoValue.length,
default: 'assert',
});
type Data =
| {
id: 1
oneValue: number
}
| {
id: 2
twoValue: string
};
const discriminateValue = type.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({
1: (o) => `${o.oneValue}!`,
2: (o) => o.twoValue.length,
default: 'assert',
});