I'm getting an error TS2339: Property 'on' does not exist on type 'ClientRequest'.
while I'm defining an extension method:
export {};
import {ClientRequest} from 'https';
declare module 'https' {
class ClientRequest {
loadData<T>(): Promise<T>;
}
}
// // eslint-disable-next-line no-extend-native
ClientRequest.prototype.loadData = async function <T>(this: ClientRequest) {
const result = new Promise<string>((resolve) => {
let data = '';
this.on('response', (res) => {
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
resolve(data);
});
});
});
return JSON.parse(await result) as T;
};