New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a typescript definition file #27
Comments
FWIW, I just created an declare module 'https-proxy-agent' {
import * as https from 'https'
namespace HttpsProxyAgent {
interface HttpsProxyAgentOptions {
host: string
port: number
secureProxy?: boolean
headers?: {
[key: string]: string
}
[key: string]: any
}
}
// HttpsProxyAgent doesnt *actually* extend https.Agent, but for my purposes I want it to pretend that it does
class HttpsProxyAgent extends https.Agent {
constructor(opts: HttpsProxyAgent.HttpsProxyAgentOptions)
}
export = HttpsProxyAgent
} And I use import * as HttpsProxyAgent from 'https-proxy-agent'
import {HttpsProxyAgentOptions} from 'https-proxy-agent'
// HttpsProxyAgent.HttpsProxyAgentOptions would also work
const opts: HttpsProxyAgentOptions = {...}
const agent = new HttpsProxyAgent(opts) |
@yonilerner Thank you man! |
* Added index.d.ts Based on: #27 (comment) (thank you @yonilerner) * Update package.json
Fixed by #66. |
@TooTallNate Might just be a intermediate change for upcoming bc breaks, but figured it might be good to share this finding just in case :) // index.d.ts - master
class HttpsProxyAgent extends https.Agent {
constructor(opts: HttpsProxyAgent.HttpsProxyAgentOptions)
}
const agent = new HttpsProxyAgent({
host,
port,
}); // fails silently when supplied to ws // index.d.ts - modified
class HttpsProxyAgent extends https.Agent {
constructor(proxy: string)
}
const agent = new HttpsProxyAgent(proxyString); // works |
I am not sure if this is the right place to talk about this, but using the workaround provided by @MichaelHindley, I get an error when passing the When trying to do fetch(url, {
method: 'POST',
headers: headers,
agent: agent,
body: data
}) I will get an error, that the (property) RequestInit.agent?: Agent | ((parsedUrl: URL) => Agent)
Type 'HttpsProxyAgent' is not assignable to type 'Agent | ((parsedUrl: URL) => Agent)'.
Property 'freeSockets' is missing in type 'HttpsProxyAgent' but required in type 'Agent'.ts(2322)
http.d.ts(361, 18): 'freeSockets' is declared here.
index.d.ts(55, 5): The expected type comes from property 'agent' which is declared here on type 'RequestInit' This can be fixed using How to properly deal with this issue? |
Using this library in typescript is impossible (with noImplicitAny option enabled) as there is no definition file.
Would you mind adding one ?
The text was updated successfully, but these errors were encountered: