TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
872 stars 229 forks source link

Typescript errors on HttpsProxyAgent (6.2 and 7.0) #200

Closed theDanielJLewis closed 1 year ago

theDanielJLewis commented 1 year ago

Using the very same example code shown in the 6.x usage (but adding the missing comma after the hostname), I keep getting TypeScript errors:

Argument of type '{ protocol: string; hostname: string; port: string; username: string; password: string; }' is not assignable to parameter of type 'string | URL'.
  Type '{ protocol: string; hostname: string; port: string; username: string; password: string; }' is missing the following properties from type 'URL': hash, host, href, origin, and 4 more.ts(2345)

This is the code:

const httpsAgent = new HttpsProxyAgent(
  {
    protocol: 'https:',
    hostname: 'myproxy.mydomain.com',
    port: '1234',
    username: 'proxyUser',
    password: 'proxyPass'
  }
);

I was on 7.0.0 so I downgraded to 6.2.1 and got the same errors.

TooTallNate commented 1 year ago

Oh ya, that was an oversight. Try passing the URL in as a string instead (or URL instance). I've updated the changelog as well.