FG
๐Ÿ”Œ APIs & SDKs

Revert #3002 - set type of data to any

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score76%
76%

Problem

Is your feature request related to a problem? Please describe. Yes. After #3002 was merged, we are now required to set explicit type definitions for every single axios request we make, even if we don't want to, because these would result in an error. Describe the solution you'd like The default type for AxiosResponse#data should be any so that we can modify it if we want, or keep it as is if we don't care about the typings for that specific request Describe alternatives you've considered As suggested in that PR, we could set the type to `any` explicitly, however, many people use typescript-eslint's no-explicit-any rule that prevents us from doing this. I believe everyone should be able to choose what types they wanna work with, because for extremely simple responses from which you only need one or two simple properties you don't always need explicit type declarations Additional context TypeScript's DOM library sets the return type of Body#toJSON to Promise<any>, so we should be following the native approach and not restricting user's options by setting a default that "most users may want", even if most users do not want this.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Revert Default Type for AxiosResponse#data to Any

Medium Risk

The merge of PR #3002 changed the default type of AxiosResponse#data from 'any' to a more restrictive type, which requires explicit type definitions for every Axios request. This change conflicts with TypeScript's flexibility and user preferences, leading to unnecessary type errors for simple responses.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify Affected Code

    Locate the AxiosResponse type definition in the codebase that was altered by PR #3002. This is typically found in the Axios type definitions file.

    typescript
    import { AxiosResponse } from 'axios';
  2. 2

    Modify Type Definition

    Change the type definition of AxiosResponse#data back to 'any'. This will allow users to either specify a type or leave it as 'any' without causing errors.

    typescript
    interface AxiosResponse<T = any> { data: T; }
  3. 3

    Run Tests

    Execute the existing test suite to ensure that reverting the type definition does not break any existing functionality or tests. Pay special attention to tests that involve Axios requests.

    bash
    npm test
  4. 4

    Update Documentation

    Revise any relevant documentation to reflect the change in default type for AxiosResponse#data, ensuring that users are aware they can now use 'any' without explicit type definitions.

    markdown
    Update README.md and TypeScript documentation.
  5. 5

    Communicate Change

    Inform the development team and users about the change in the default type for AxiosResponse#data, highlighting the benefits of this flexibility in type handling.

    markdown
    Send an email or update the changelog.

Validation

Confirm that the Axios requests can be made without explicit type definitions and that the application compiles without type errors. Additionally, ensure that all unit tests pass successfully.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi