I have a small proxy server developed in node with js and I'm trying to rewrite it in typescript.
I have the following code:
http.createServer(onRequest).listen(config.port);console.log(`proxy listening on port ${config.port}`)function onRequest(local_req, local_res) { console.log('serve: '+ local_req.url); const url = config.forward_url + local_req.url[...]
ANd typescript complains about
Parameter 'local_req' implicitly has an 'any' type.ts(7006)Parameter 'local_res' implicitly has an 'any' type.ts(7006)
I already did npm i @types/node -D
I see that the definition of the createServer method is like the following:
function createServer(options: ServerOptions, requestListener?: RequestListener): Server;
But I don't have the definition of RequestListener
I google it and I find it here (I thought it should had been installed npm i @types/node -D
), like this:
export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server;
Then I look for the definition of ServerRequest and it's here, but I don't have it available on my machine.
I guess that the definition I have goolged is not the one I have installed with npm.
I don't get how to deal with the definitions of node types.
Can anybody give me a hint about how to download the definitions of the types you are using in node?