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

219
Vistas
How to predefine object with element as an array <string> type?

I have an object, and i need to define in this object sub element, which will be as an array. But how do i define it's type? Without type definition it throws error.

Implicitly has any[]

let someObject = {
  somePropety: {
    A : 0,
    B : 0,
    C : []<string>,
  }
}

Does anyone know how to asign C element an array of string type ?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You're looking for string[]. However, it doesn't look like your example is a type definition?

I would write it like this:

let someObject: { somePropety: { A: number; B: number; C: string[] } } = {
        somePropety: {
          A: 0,
          B: 0,
          C: []
        }
}; 
about 4 years ago · Juan Pablo Isaza Denunciar

0

You seem to be looking for

let someObject = {
  someProperty: {
    A: 0,
    B: 0,
    C: [] as string[],
  },
};

Alternatively, you can declare the type of the entire someObject variable (see @wooooooo's or @ksav's answers for that) instead of using a type assertion on the empty array literal.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are trying to define C as an array of strings, you can do:

C: string[];

or using a generic array type:

C: Array<string>

You can find more detail on TypeScript basic types here

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