Получение "Невозможно вызвать выражение, тип которого не имеет подписи вызова", когда я запускаю команду "yarn typedo c" - PullRequest
0 голосов
/ 19 февраля 2020

Функция validateUrl первоначально делает запрос HEAD, чтобы проверить, существует ли ресурс, и возвращает true, если он получает ответ об успешном выполнении. Однако, если HEAD-запросы отключены для некоторых ресурсов, я пытаюсь получить GET-запрос. Поскольку я не хочу загружать ресурс, я использую низкоуровневый http / https API Node.

// tslint:disable-next-line:import-name
import Axios from "axios";
import * as http from "http";
import * as https from "https";
import { URL } from "url";
import { BadRequestError } from "../types";
/**
 * Make a head request with the requested URL and validate it
 */
export class ValidateUrlService {

  public readonly validateUrl = async (
requestedUrl: string
  ): Promise<boolean|{}> => {
return new Promise((resolve, reject) => {
  // Make a HEAD request first to check if the resource exists
  Axios.head(requestedUrl)
    .then(() => {
      resolve(true);
    })
    .catch(() => {
      // Make a GET request to check if the resource exists
      const httpClient = this.getClient(requestedUrl);
      const request = httpClient.get(requestedUrl, (response) => {
        request.abort();
        resolve(
          response.statusCode !== undefined &&
            response.statusCode >= 200 &&
            response.statusCode <= 299
        );
      });
      request.on("error", () => {
        resolve(false);
      });
      request.end();
    });
 });
};

/**
* Gets an HTTP client based on the protocol of resource URL
* @param resourceUrl the resource url
*/
private readonly getClient = (
 resourceUrl: string
): typeof http | typeof https => {
const url = new URL(resourceUrl);
switch (url.protocol) {
  case "https:":
    return https;
  // tslint:disable-next-line:no-http-string
  case "http:":
    return http;
  default:
    throw new BadRequestError(
      `URL scheme [${
        url.protocol
      }] for media or supporting documents is not supported`,
      true
    );
  }
 };
}

Эта функция работает должным образом, но когда Jenkins запускает команду yarn typedoc --includeDeclarations --out reports/docs --readme ../README.md --mode modules --excludeExternals src/, я получаю ошибку ниже, и, следовательно, моя сборка завершается неудачно. Любое предложение?

Using TypeScript 3.1.6 from api/node_modules/typedoc/node_modules/typescript/lib
Error: /api/src/services/validate-url.ts(30)
Cannot invoke an expression whose type lacks a call signature. Type '{ (options: string | URL |         RequestOptions, callback?: ((res: IncomingMessage) => void) | undefined): ClientRequest; (url: string |     URL, options: RequestOptions, callback?: ((res: IncomingMessage) => void) | undefined): ClientRequest; } | { ...; }' has no compatible call signatures.
Error: /api/src/services/validate-url.ts(30)
Parameter 'response' implicitly has an 'any' type. 
...