I've got this function:
function stackPlayer(stack){
}
The stack
parameter can have one of the following forms only:
- a function that takes
req
,res
, andnext
as arguments. - a function that takes
req
,res
, andnext
as arguments, and returns a function that also takesreq
,res
, andnext
. - a function that takes
req
,res
, andnext
as arguments, and returns an array of functions that also takereq
,res
, andnext
. - an array of functions that take
req
,res
, andnext
as arguments.
For example:
// Examples of valid arguments:
(req, res, next) => {} // or
(req, res, next) => (req, res, next) => {} // or
(req,res,sNext) => [(req,res,sNext)=>{}] // or
[(req,res,sNext)=>{}]
To simplify the type of the parameter in the function, I came up with the following solution which makes it easier to read and understand:
type Smiddleware = <T = void>(req: Request, res: Response, next: NextFunction) => T
type Stack = Smiddleware<void> | Smiddleware<Smiddleware> | Smiddleware<Smiddleware[]> | Smiddleware[]
This approach is more concise and clear, but unfortunately not valid.