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

140
Views
How do you understand WebStorm's function interfaces?

I am having trouble understanding some functions, and their interfaces. IE:

ReadonlyArray<unknown>.map( 
    callbackfn: (value: unknown, index: number, array: unknown[]) => unknown,
    thisArg?: any): unknown[]

This is what WebStorm displays when I hover over a .map() function. I understand that .map() takes a specified callback function as a parameter, but what do => unknown, and thisArg?: any represent?

Likewise when I hover over a forEach() function, the popup looks like this:

ReadonlyArray<unknown>.forEach(
     callbackfn: (value: unknown, index: number, array: unknown[]) => void,
     thisArg?: any): void

forEach also takes a callback function as a parameter, but what does => void, thisArg?: any): void represent?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

// the `.map` function is member of the generic type ReadonlyArray<unknown>. Where unknown is the type of the elements of the array
ReadonlyArray<unknown>.map( 
    // first argument is a callback function. The first argument of the callback is value, of type unknown, the second is index of type number, and so on
    callbackfn: (value: unknown, index: number, array: unknown[]) 
       // this parts means that the callback should return a value of type unknown
       => unknown,
    // .map takes a second arguments called thisArg of any type. The ? means that the argument is optional
    thisArg?: any)
    // .map returns an array of type unknown
    : unknown[]

The type is unknown because it depends on the type of the elements present in the array on which .map is applied. If it is an array of object, the unknown type will be object

Similarly, forEach takes a first argument which is a callback. But the callback returns nothing, hence you have => void.

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