I haven't found any TypeScript definitions for superagent-proxy. So when I try to compile my TypeScript application to JavaScript, I get the error message:
ts: Property 'proxy' does not exist on type 'SuperAgentRequest'.
import * as request from 'superagent';
import * as withProxy from 'superagent-proxy';
withProxy(request);
request
.get(...)
.proxy(proxy)
I have created a file with declarations, but I don't know what more to do.
declare module 'superagent-proxy';
I guess I want to define some higher order function that takes a superagent and returns a superagent with proxy somehow.
This is my best attempt this far:
import * as request from 'superagent';
declare module 'superagent-proxy' {
interface SuperAgentRequestWithProxy extends request.SuperAgentStatic {
proxy(url: string): SuperAgentRequestWithProxy;
}
}
But it doesn't work and I'm not even sure its close to correct.
Invalid module name in augmentation. Module 'superagent-proxy' resolves to an untyped module at '.../node_modules/superagent-proxy/index.js', which cannot be augmented
you need to add the type dependency as well, importing only the super agent proxy dependency is not sufficient, you need to have two imports :
"superagent-proxy": "^2.1.0", under dependencies
"@types/superagent-proxy": "^2.0.0", under dev dependencies
To install
npm i superagent
npm i superagent-proxy
npm i --save-dev suuperagent-proxy
To use
import * as superagent from 'superagent';
import enableProxy from 'superagent-proxy';
enableProxy(superagent);
Then:
await superagent.get(...).proxy(proxyUrl)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With