Relative Content

Tag Archive for typescriptabstraction

Typescript: define field as a tag for type

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}