I am working on a typescript react project and have found myself repeating myself when writing dropdown menus. Each option in the menu is formatted as a pair {value: T, label: string}
where T
is a type I’m selecting from. In many of my menus, I choose the label from a field within the object. Ex: items.map(item => {value: item, label: item.name}
As I understand it, there are many abstraction methods (abstract classes, decorators, etc.) in Typescript I could use to remove this repetition. Is there a preferred one?