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

Should wx.request have a type parameter? #138

Closed
geoffliu opened this issue Jun 10, 2020 · 1 comment
Closed

Should wx.request have a type parameter? #138

geoffliu opened this issue Jun 10, 2020 · 1 comment

Comments

@geoffliu
Copy link

Currently, the res.data field in the success callback has type 'string | Record<string, any> | ArrayBuffer. This means to properly use this, I have to do this (pseudocode):

if (typeof res.data is string or array buffer) {
  raise error
}
use res.data as type any object

There are two problems with this. 1. I know my backend API returns JSON in the success case, so the string and ArrayBuffer cases are never actually in use. 2. res.data is simply any object, I can't specify its type without doing an explicit cast every time.

Proposal: define wx.request as something similar to the following:

request<T>({
  success: ({ data: T, ... }) => void,
  ...
})

While we're at it, it'd be useful to define an error type as well, for the fail callback.

@SgLy
Copy link
Contributor

SgLy commented Jan 15, 2021

wx.request can have a generic, this will be tracked in #177, closing duplicated

@SgLy SgLy closed this as completed Jan 15, 2021
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

2 participants