DEV Community

Discussion on: Developing an Express Application Using TypeScript

Collapse
 
edportscher profile image
Edwin

I have a question, I am just learning typescript, I do not understand this.

private middlewares(middleWares: { forEach: (arg0: (middleWare: any) => void) => void; })

what does { forEach: (arg0: (middleWare: any) => void) => void; } this do?

why could you not do this?

private middlewares(middleWares: any)

Collapse
 
heritiermwalila profile image
Heritier Mwalila

@edwin , this is very easy to understand if you already understand type of interface in typescript
You can write the same thing like this
interface arg{
(ar)=>void
}
interface middlewareInter{
forEach:(argument:arg)=>void // look at forEach function in js how it written
}
private middlewares(middlew:middlewareInter){
}

it return void because don't wanna handle the result there. void is a type in typescript which just tell that the function does not return anything