Skip to content

Comments

Update TypeScript typings with generic type parameters (#1061)#10

Open
MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
pr_030_after
Open

Update TypeScript typings with generic type parameters (#1061)#10
MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
pr_030_after

Conversation

@MitchLewis930
Copy link

@MitchLewis930 MitchLewis930 commented Jan 29, 2026

PR_030

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced TypeScript support for HTTP requests and responses. API methods now support generic type parameters, enabling developers to specify response data types and receive improved type inference and IDE autocompletion for better type safety.

✏️ Tip: You can customize this high-level summary in your review settings.

Daniel Fischer and others added 2 commits August 29, 2017 20:53
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

The Axios TypeScript type declarations are converted to support generics, enabling strongly-typed response data handling. Key interfaces (AxiosResponse, AxiosPromise) and methods (request, get, post, put, patch) now accept generic type parameters with defaults to any. Test examples demonstrate the generic usage.

Changes

Cohort / File(s) Summary
TypeScript Type Declarations
index.d.ts
Converted AxiosResponse, AxiosPromise, and AxiosInstance method signatures to generic types with default any parameter, enabling type-safe response handling. AxiosAdapter now returns AxiosPromise<any>.
Generic Usage Examples
test/typescript/axios.ts
Added typed example code demonstrating generic HTTP method calls (get<User>, post<User>, put<User>, patch<User>) with a User interface and response handler for validating generic type integration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Generics hop through our types so grand,
AxiosPromise now understands,
Response makes data pure and true,
Where types flow freely, old and new!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding generic type parameters to TypeScript typings, which aligns with the PR objectives and the substantial changes to index.d.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@index.d.ts`:
- Around line 104-110: The delete and head method signatures in index.d.ts lack
generic type parameters; update the methods named delete and head to accept a
generic type parameter (e.g., <T = any>) and make their return types
AxiosPromise<T>, matching the pattern used by get/post/put/patch so callers can
specify the response type; modify the signatures for the delete and head
functions (the ones currently declared as delete(url: string, config?:
AxiosRequestConfig): AxiosPromise and head(url: string, config?:
AxiosRequestConfig): AxiosPromise) to include the generic and return
AxiosPromise<T>.
🧹 Nitpick comments (1)
index.d.ts (1)

113-116: Consider adding generic type parameters to AxiosStatic callable signatures.

The AxiosStatic interface's callable signatures on lines 114-115 return AxiosPromise without a generic type parameter. For full consistency with the updated instance methods, these could also accept generics.

♻️ Optional enhancement for callable signatures
 export interface AxiosStatic extends AxiosInstance {
-  (config: AxiosRequestConfig): AxiosPromise;
-  (url: string, config?: AxiosRequestConfig): AxiosPromise;
+  <T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
+  <T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
   create(config?: AxiosRequestConfig): AxiosInstance;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 638804a and 7133141.

📒 Files selected for processing (2)
  • index.d.ts
  • test/typescript/axios.ts
🧰 Additional context used
🧬 Code graph analysis (1)
test/typescript/axios.ts (1)
index.d.ts (1)
  • AxiosResponse (47-53)
🔇 Additional comments (2)
index.d.ts (1)

47-48: Good addition of generic type parameters.

The generic typing for AxiosResponse<T = any> and AxiosPromise<T = any> is well-implemented with appropriate defaults for backward compatibility.

Also applies to: 62-62

test/typescript/axios.ts (1)

100-137: Good demonstration of generic type usage.

The test examples effectively validate the new generic typings by:

  • Defining a User interface with expected properties
  • Creating a typed handler handleUserResponse that accesses response.data.id and response.data.name with type safety
  • Demonstrating generic usage across get<User>, post<User>, put<User>, and patch<User> methods

Consider adding examples for instance.request<User>(config) to demonstrate generic usage on the request method as well.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +104 to +110
request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
head(url: string, config?: AxiosRequestConfig): AxiosPromise;
post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

delete and head methods are missing generic type parameters.

The delete and head methods on lines 106-107 have not been updated with generic type parameters, unlike get, post, put, and patch. This creates an inconsistency where users cannot specify response types for these methods.

🔧 Proposed fix to add generics to delete and head
   request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
   get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
-  delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
-  head(url: string, config?: AxiosRequestConfig): AxiosPromise;
+  delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
+  head<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
   post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
   put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
   patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
head(url: string, config?: AxiosRequestConfig): AxiosPromise;
post(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
put(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
patch(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
delete<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
head<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
🤖 Prompt for AI Agents
In `@index.d.ts` around lines 104 - 110, The delete and head method signatures in
index.d.ts lack generic type parameters; update the methods named delete and
head to accept a generic type parameter (e.g., <T = any>) and make their return
types AxiosPromise<T>, matching the pattern used by get/post/put/patch so
callers can specify the response type; modify the signatures for the delete and
head functions (the ones currently declared as delete(url: string, config?:
AxiosRequestConfig): AxiosPromise and head(url: string, config?:
AxiosRequestConfig): AxiosPromise) to include the generic and return
AxiosPromise<T>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants