Skip to content

[Documentation] Add TypeScript example for custom instance with interceptors #7261

@SIVALANAGASHANKARNIVAS

Description

@SIVALANAGASHANKARNIVAS

Description

The documentation would benefit from a comprehensive TypeScript example showing how to create a custom axios instance with properly typed request/response interceptors.

Current Documentation Gap

While the README covers basic usage, TypeScript users often struggle with:

  • Properly typing custom axios instances
  • Adding type-safe interceptors
  • Handling error types in interceptors

Suggested Addition

Add a TypeScript section in the README with an example like:

import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse } 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;
  }
);

Benefits

  1. Reduces common TypeScript errors for new users
  2. Promotes type-safe API client patterns
  3. Helps developers using axios in React/Node projects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions