Incoming message already has getHeader method, we can make interface like:
declare function accepts(req: Pick<IncomingMessage, 'getHeader'>): Accepts
And then we can use it now too for IncomingMessage:
const req = new IncomingMessage(/* ... */);
// no changes in usage
const accept = accepts(req);
And also we can use it easy with Request instance or any other request value:
const req = new Request(/* ... */);
// easy making wrapper object for use with Request
const accept = accepts({
getHeader: headerName => req.headers.get(headerName)
});
Idea 3
Maybe we can make just TypeScript types of this library more abstract, for example:
declare function accepts(req: Pick<IncomingMessage, 'headers'>): Accepts
Hi, i want to use this library with not only
IncomingMessage
instances.Node.js 16+ has Fetch API now and it has global constructors such as
Request
,Response
,Headers
and other.Also i see that implementation of this library uses only
headers
field fromreq
parameter.Idea 1
Maybe we can make this library more abstract, for example we can make next interface changes:
With this interface we can use this library with instance of any class:
Idea 2
Incoming message already has
getHeader
method, we can make interface like:And then we can use it now too for
IncomingMessage
:And also we can use it easy with
Request
instance or any other request value:Idea 3
Maybe we can make just TypeScript types of this library more abstract, for example: