Update TypeScript typings with generic type parameters (#1061)#10
Open
MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
Open
Update TypeScript typings with generic type parameters (#1061)#10MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
MitchLewis930 wants to merge 2 commits intopr_030_beforefrom
Conversation
…ethods & AxiosResponse
Update TypeScript typings with generic type parameters
There was a problem hiding this comment.
Pull request overview
This PR enhances the TypeScript test suite by adding comprehensive type-safety demonstrations for Axios HTTP methods. The changes showcase how the library supports generic type parameters to provide compile-time type checking for API responses.
Changes:
- Added a
Userinterface to demonstrate typed API responses - Created typed HTTP method calls using generic type parameters (
<User>) - Introduced
handleUserResponsefunction to demonstrate type-safe response handling
Comments suppressed due to low confidence (1)
test/typescript/axios.ts:1
- Inconsistent indentation detected in promise chains. These lines use tabs while the existing promise chains in the file (lines 88-98) use spaces. Please use spaces consistently with the existing code style.
import axios, {
Comment on lines
+107
to
+129
| console.log(response.data.id); | ||
| console.log(response.data.name); | ||
| console.log(response.status); | ||
| console.log(response.statusText); | ||
| console.log(response.headers); | ||
| console.log(response.config); | ||
| }; | ||
|
|
||
| axios.get<User>('/user?id=12345') | ||
| .then(handleUserResponse) | ||
| .catch(handleError); | ||
|
|
||
| axios.get<User>('/user', { params: { id: 12345 } }) | ||
| .then(handleUserResponse) | ||
| .catch(handleError); | ||
|
|
||
| axios.post<User>('/user', { foo: 'bar' }) | ||
| .then(handleUserResponse) | ||
| .catch(handleError); | ||
|
|
||
| axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } }) | ||
| .then(handleUserResponse) | ||
| .catch(handleError); |
There was a problem hiding this comment.
Inconsistent indentation detected. The function body uses tabs while the rest of the file appears to use spaces for indentation. Please use spaces consistently with the existing code style.
Suggested change
| console.log(response.data.id); | |
| console.log(response.data.name); | |
| console.log(response.status); | |
| console.log(response.statusText); | |
| console.log(response.headers); | |
| console.log(response.config); | |
| }; | |
| axios.get<User>('/user?id=12345') | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.get<User>('/user', { params: { id: 12345 } }) | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.post<User>('/user', { foo: 'bar' }) | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } }) | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| console.log(response.data.id); | |
| console.log(response.data.name); | |
| console.log(response.status); | |
| console.log(response.statusText); | |
| console.log(response.headers); | |
| console.log(response.config); | |
| }; | |
| axios.get<User>('/user?id=12345') | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.get<User>('/user', { params: { id: 12345 } }) | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.post<User>('/user', { foo: 'bar' }) | |
| .then(handleUserResponse) | |
| .catch(handleError); | |
| axios.post<User>('/user', { foo: 'bar' }, { headers: { 'X-FOO': 'bar' } }) | |
| .then(handleUserResponse) | |
| .catch(handleError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR_030