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

175
Vistas
Typescript array being passed as object, testing with typeof operator

This is a dumb question but I have a function that does:

export function parseSomething(someList: string[]): string[] {
    someList.forEach((someField: string) => {
        console.log(typeof someField)
    })

someField is being read as an object. Why? The object being passed to this function is a string array.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The typeof operator returns a string indicating the type of the unevaluated operand. It does work on execution time, so there is no TypeScript at this point. And there is no array type in JavaScript, as arrays are objects. You can read on mdn for more about JavaScript types.

Arrays exist only while writing code with your linter and on compilation time with your compilator as it's a TypeScript only type. You can use Array.isArray() to test if someField is an array on execution time, like so as an example:

console.log(Array.isArray(someField))
about 4 years ago · Santiago Trujillo 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