2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

docs: add typescript example for custom instance (#7288)

* docs: add abort controller example

* docs: add typescript example for custom instance

* Update server.js

* Delete examples/abort-controller/server.js

* Delete examples/abort-controller/index.html

---------

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Akash Dhar Dubey
2025-12-09 14:27:25 +05:30
committed by GitHub
parent a4230f5581
commit 0bf4608d60
+19
View File
@@ -1778,6 +1778,25 @@ If use ESM, your settings should be fine.
If you compile TypeScript to CJS and you cant use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`. If you compile TypeScript to CJS and you cant use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`.
If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`. If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
You can also create a custom instance with typed interceptors:
```typescript
import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
const apiClient: AxiosInstance = axios.create({
baseURL: 'https://api.example.com',
timeout: 10000,
});
apiClient.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
// Add auth token
return config;
}
);
```
## Online one-click setup ## Online one-click setup
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online. You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.