对象在 catch 块上属于 'unknown' 类型

Object is of type 'unknown' on catch block

我正在尝试创建一个 axios 抽象,但我在 catch 块上遇到了这个错误。

对象的类型为 'unknown'。

import axios, { AxiosResponse } from "axios";
import { injectable } from "inversify";
import { HttpRequest, HttpResponse, IHttp } from "../../interfaces/Ihttp";

@injectable()
export class AxiosHttpClient implements IHttp {
  async request(params: HttpRequest): Promise<HttpResponse> {
    let axiosResponse: AxiosResponse;

    try {
      axiosResponse = await axios.request({
        url: params.url,
        method: params.method,
        data: params.body,
        headers: params.headers,
      });
    } catch (error) {
      axiosResponse = error.response;
    }

    return {
      statusCode: axiosResponse.status,
      data: axiosResponse.data,
    };
  }
}

我解决了在 tsconfig.json

中将 useUnknownInCatchVariables 选项设置为 false 的问题