Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better specify type for put/post data params #3599

Closed
Calamari opened this issue Jan 27, 2021 · 2 comments
Closed

Better specify type for put/post data params #3599

Calamari opened this issue Jan 27, 2021 · 2 comments

Comments

@Calamari
Copy link

Since #3549 (comment) made it clear that post/put/patch calls have to use objects (or probable also stringified versions of those), the TypeScript type should reflect this fact, to avoid more problems/bug reports regarding this.

So maybe instead of currently doing this (index.t.ds)

  post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
  patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;

it is useful to do

  post<T = any, R = AxiosResponse<T>>(url: string, data?: string | object, config?: AxiosRequestConfig): Promise<R>;
  put<T = any, R = AxiosResponse<T>>(url: string, data?: string | object config?: AxiosRequestConfig): Promise<R>;
  patch<T = any, R = AxiosResponse<T>>(url: string, data?: string | object, config?: AxiosRequestConfig): Promise<R>;

Expected behavior

A clear and concise description of what you expected to happen.

Environment

  • Axios Version 0.21.0

Side note:
I also wonder why the decision is made, since if I would send out an application/json request, I would be able to send everything as payload that is or can be stringified as JSON (which also includes just a boolean (e.g. false) or a number (e.g. 0).

@github-actions
Copy link
Contributor

Hello! 👋

This issue is being automatically closed because it does not follow the issue template. Please read the issue template carefully and follow all of the instructions when opening a new issue.

Thanks

@Calamari
Copy link
Author

🤷

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

No branches or pull requests

1 participant