Creating a Helper Function for Type Matching in TypeScript
Hi There,
How I can create helper function for this case
I tried to use identity function but it broke types at the result
How I can create helper function for this case
I tried to use identity function but it broke types at the result
type valueT: 'IsA' | 'IsAReverse' | 'DerivedFrom' | 'DerivedFromReverse' | 'IsBrandedFor' | 'Variety' | 'AggregatesTo' | 'CanBeUpgradedTo' | 'IsAlternativeTo'
const test = (val:valueT)=> Match.value(val).pipe(
Match.when('IsA', (v) => v),
Match.when('IsAReverse', constant('IsA' as const)),
Match.when('DerivedFrom', (v) => v),
Match.when('DerivedFromReverse', constant('DerivedFrom' as const)),
Match.when('IsBrandedFor', (v) => v),
Match.when('Variety', (v) => v),
Match.when('AggregatesTo', (v) => v),
Match.when('CanBeUpgradedTo', (v) => v),
Match.when('IsAlternativeTo', (v) => v),
Match.exhaustive
); type valueT: 'IsA' | 'IsAReverse' | 'DerivedFrom' | 'DerivedFromReverse' | 'IsBrandedFor' | 'Variety' | 'AggregatesTo' | 'CanBeUpgradedTo' | 'IsAlternativeTo'
const test = (val:valueT)=> Match.value(val).pipe(
Match.when('IsA', (v) => v),
Match.when('IsAReverse', constant('IsA' as const)),
Match.when('DerivedFrom', (v) => v),
Match.when('DerivedFromReverse', constant('DerivedFrom' as const)),
Match.when('IsBrandedFor', (v) => v),
Match.when('Variety', (v) => v),
Match.when('AggregatesTo', (v) => v),
Match.when('CanBeUpgradedTo', (v) => v),
Match.when('IsAlternativeTo', (v) => v),
Match.exhaustive
);