Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Typescript: type is object where property names are unknown

I am currently making a component in React and one of the properties is called 'initNavData'. This is an object where the property names will always be different names and there are an unknown amount of these properties. Each of them will have the same structure though. How can I create a type for this?

I saw the [x: string] suggestion, but will this allow for an unlimited amount of properties?

interface WizardProps {
  id: string;
  // parentWizard: string
  isSubwizard: boolean;
  wizardName: string;
  initNavData: {
    [x: string]: {
      label: string;
      status: string;
      current: boolean;
      active: boolean;
      icon: string;
      key: string;
    }
  }
}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

yeah, you can use index signatures. As TypeScript handbook says:

Sometimes you don’t know all the names of a type’s properties ahead of time, but you do know the shape of the values.

In those cases you can use an index signature to describe the types of possible values

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda