Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda