This PR pulls in implementation from nextjs-handler-middleware for the pages directory approach to API handlers.
It also updates and simplifies the typing strategy.
Request types are now explicitly provided by wrappers, and
When two wrappers are merged, their request types are merged together.
Other
It also solves the problem of not being able to override the any type on NextApiRequest['body'] by introducing a SpecificIntersection type the prefers the more specific type in an intersection with another type.
This allows for middleware like validated to produce a request with a specific body type on the other side of the middleware without having to introduce a new property on the request.
Overview
This PR pulls in implementation from nextjs-handler-middleware for the pages directory approach to API handlers.
Other
It also solves the problem of not being able to override the
any
type onNextApiRequest['body']
by introducing aSpecificIntersection
type the prefers the more specific type in an intersection with another type.This allows for middleware like
validated
to produce a request with a specific body type on the other side of the middleware without having to introduce a new property on the request.