Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!