繁体   English   中英

获取对象键类型打字稿

[英]Get type of object keys typescript

有这样的对象,我的问题是如何使用标签作为索引和打字稿不抱怨

const en = {
    "account.options.global.description": "Set your default language and theme",
    "account.options.global.title": "Global preferences",
    "account.options.login.description": "Update your password and secure your account",
    "account.options.login.section.button.alternatetitle": "Set password",
    "account.options.login.section.button.title": "Update password",
    "account.options.login.section.login": "Login",
}

export interface CountriesI {
  value: Countries;
  label: string --> what should be correct;
}

const countries: CountriesI[] = [
  {value: Countries.ARG, label: 'common.countries.options.argentina'},
  {value: Countries.BOL, label: 'common.countries.options.bolivia'},
  {value: Countries.BRA, label: 'common.countries.options.brasil'},
  {value: Countries.COL, label: 'common.countries.options.colombia'},
  {value: Countries.CHL, label: 'common.countries.options.chile'},
  {value: Countries.ECU, label: 'common.countries.options.ecuador'},
  {value: Countries.GUY, label: 'common.countries.options.guyana'},
  {value: Countries.MEX, label: 'common.countries.options.mexico'},]

//complains index is not a type

countries.map((element) => {
return {...element,  en[element.label]}
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM