[Summary] I am looking to dynamically expand my type in TypeScript based on an initial set of values. I want to avoid managing separate arrays/types and instead extend all strings in my type with '_max'.
type ExtendedValueTypes = 'money' | 'land' | 'money_max' | 'land_max';
// dynamically from
type ValueTypes = 'money' | 'land';
I have a list of values
const values = ['money', 'land'] as const;
type ValueTypes = typeof values[number];
// equals ValueTypes = 'money' | 'land';
Now I want to dynamically extend my type to equal
type ExtendedValueTypes = 'money' | 'money_max' | 'land' | 'land_max';
To achieve this, I need a type declaration that automatically appends '_max' to all the strings in my type definition.
const check = (type: ValueTypes) => 'some return'
//works
check('money');
// does not work but should
check('money_max')