Tengo problemas para entender algunas funciones y sus interfaces. ES DECIR:
ReadonlyArray<unknown>.map( callbackfn: (value: unknown, index: number, array: unknown[]) => unknown, thisArg?: any): unknown[] Esto es lo que muestra WebStorm cuando paso el mouse sobre una función .map() . Entiendo que .map() toma una función de devolución de llamada específica como parámetro, pero ¿qué => unknown y thisArg?: any represent?
Del mismo modo, cuando paso el cursor sobre una función forEach() , la ventana emergente se ve así:
ReadonlyArray<unknown>.forEach( callbackfn: (value: unknown, index: number, array: unknown[]) => void, thisArg?: any): void forEach también toma una función de devolución de llamada como parámetro, pero ¿qué representa => void, thisArg?: any): void ?
// 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[] El tipo es desconocido porque depende del tipo de los elementos presentes en la matriz en la que se aplica .map . Si es una matriz de objetos, el tipo desconocido será object
De manera similar, forEach toma un primer argumento que es una devolución de llamada. Pero la devolución de llamada no devuelve nada, por lo tanto, tiene => void .