选择特定的键值对作为typescript中的类型

选择特定的键值对作为typescript中的类型,typescript,typescript2.0,Typescript,Typescript2.0,在typescript中,我知道我可以创建一个类型,并使用Pick选择特定的键值对作为类型。但无论如何,我只是从对象中选择 /** select from type type variableType = {option: string, value:string, url:string} const variable: Pick<variableType, "option" | "value">[] = [ { option: 'a', value: 'a_v', }, {

在typescript中,我知道我可以创建一个类型,并使用Pick选择特定的键值对作为类型。但无论如何,我只是从对象中选择

/**
select from type
type variableType = {option: string, value:string, url:string}
const variable: Pick<variableType, "option" | "value">[] = [
{
  option: 'a',
  value: 'a_v',
},
{
  option: 'b',
  value: 'b_v',
},
];

console.log(variable)
*/

maybe something like this?
const variable: Pick{option: string, value:string, url:string}[] = [
{
  option: 'a',
  value: 'a_v',
},
{
  option: 'b',
  value: 'b_v',
},
];
console.log(variable)

似乎您正在尝试使用文字类型:

const variable: Pick<{option: string, value: string, url?: string}>[] = [
  {option: 'a', value: 'a_v'},
  {option: 'b', value: 'b_v'},
];