What is the way to make the TS compiler recognize the data type of interface without introducing Axios?

A project, using Axios+Typescript, I have such a piece of code.

import { AxiosRequestConfig, AxiosResponse } from "axios"

function requestIntercepter(config: AxiosRequestConfig): (AxiosRequestConfig | Promise<AxiosRequestConfig>) {
  return config
}

in order to recognize the type of config, I must it"s hard for me to introduce two interface,. Is there any way to identify these two data types without introduction:

tried methods:

  1. download @ types/axios library (discarded and not maintained)
  2. added rootType: "node_modules/axios/index.d.ts" to tsconfig.json
  3. use / < reference path= ".. / node_modules/axios/index.d.ts" >
  4. in your type declaration file

none of the above three methods work, is there no way to solve this problem? Obsessive-compulsive disorder looks really uncomfortable.


write anonymous functions directly without citing any interface. You can hint in the correct code

.
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

  1. you must declare a type to access the properties and methods of the corresponding type
  2. axios has an official index.d.ts, that is downloaded automatically when you npm install axios, and no other action is required to deal with the declaration file

index.d.ts

Menu