网站搜索

typescript - 从对象数组创建联合类型


我有一个对象数组:

const arr = [{
  value: 'value1',
  key: 'key1'
}, {
  value: 'value2',
  key: 'key2'
}]

我想实现的是获取一个联合类型,该类型包含 value 键的值。

type Values = 'value1' | 'value2';

我如何定义类型以便从对象数组中自动生成它?