Skip to content

Commit

Permalink
fix: fix request types and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 8, 2021
1 parent 917e9ce commit 8af95e9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import npm from "npm"
import request from "request"
import request, { Options, RequestCallback } from "request"
import * as config from "./apm"

function loadNpm(callback) {
function loadNpm(callback: Parameters<(typeof npm)["load"]>[1]) {
const npmOptions = {
userconfig: config.getUserConfigPath(),
globalconfig: config.getGlobalConfigPath(),
}
return npm.load(npmOptions, callback)
}

function configureRequest(requestOptions, callback) {
function configureRequest(requestOptions: Options, callback: () => void) {
return loadNpm(function () {
let left
if (requestOptions.proxy == null) {
Expand All @@ -40,9 +40,9 @@ function configureRequest(requestOptions, callback) {
})
}

export function get(requestOptions, callback) {
export function get(requestOptions: Options & { retries?: number }, callback: RequestCallback) {
return configureRequest(requestOptions, function () {
let retryCount = requestOptions.retries != null ? requestOptions.retries : 0
let retryCount = ("retries" in requestOptions) ? requestOptions.retries : 0
let requestsMade = 0
const tryRequest = function () {
requestsMade++
Expand All @@ -63,15 +63,15 @@ export function get(requestOptions, callback) {
})
}

export function del(requestOptions, callback) {
export function del(requestOptions: Options, callback: RequestCallback) {
return configureRequest(requestOptions, () => request.del(requestOptions, callback))
}

export function post(requestOptions, callback) {
export function post(requestOptions: Options, callback: RequestCallback) {
return configureRequest(requestOptions, () => request.post(requestOptions, callback))
}

export function createReadStream(requestOptions, callback) {
export function createReadStream(requestOptions: Options, callback: { (readStream: any): any; (arg0: request.Request): void }) {
return configureRequest(requestOptions, () => callback(request.get(requestOptions)))
}

Expand Down

0 comments on commit 8af95e9

Please sign in to comment.