Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda