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

171
Visualizações
Proper way to declare json object (typescript)

I have the following json file with data:

[{
    "sectionKey": "key1",
    "sectionName": "name",
    "content": []
  },
  {
    "sectionKey": "key2",
    "sectionName": "name",
    "content": []
  }
]

My question is: how to declare the content of the array in typescript? like "Type"[]. Please do not suggest using any[] since it removes all type checking provided by TypeScript.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

interface CoolObject {
  sectionKey: string;
  sectionName: string;
  content: Array<any>;
}

const greatArray: CoolObject[] = [
  {
    sectionKey: 'key1',
    sectionName: 'name',
    content: [],
  },
  {
    sectionKey: 'key2',
    sectionName: 'name',
    content: [],
    foobar: 'something' // not assignable to type 'CoolObject'
  },
];

If it's the 'content' poperty you're trying to typehint you can use Array<YourType> or YourType[] too.

about 4 years ago · Juan Pablo Isaza 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