mirror of
https://github.com/tenrok/axios.git
synced 2026-06-02 16:04:10 +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:
@@ -1778,6 +1778,25 @@ If use ESM, your settings should be fine.
|
||||
If you compile TypeScript to CJS and you can’t 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"`.
|
||||
|
||||
|
||||
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
|
||||
|
||||
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
|
||||
|
||||
Reference in New Issue
Block a user