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

关于 useAxios, 强制类型 AxiosRequestConfig<D> 而不是 <any> #2204

Closed
4 tasks done
KeJunMao opened this issue Sep 15, 2022 · 3 comments
Closed
4 tasks done

关于 useAxios, 强制类型 AxiosRequestConfig<D> 而不是 <any> #2204

KeJunMao opened this issue Sep 15, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@KeJunMao
Copy link

Clear and concise description of the problem

useAxios 目前仅支持一个泛型参数作为response类型,希望可以为AxiosRequestConfig也新增一个类型参数来定义data属性的类型

Suggested solution

interface StrictUseAxiosReturn<T, D> extends UseAxiosReturn<T> {
  /**
   * Manually call the axios request
   */
  execute: (
    url?: string | AxiosRequestConfig<D>,
    config?: AxiosRequestConfig<D>
  ) => PromiseLike<StrictUseAxiosReturn<T, D>>;
}
declare function useAxios<T = any, D = any>(
  url: string,
  config?: AxiosRequestConfig,
  options?: UseAxiosOptions
): StrictUseAxiosReturn<T, D> & PromiseLike<StrictUseAxiosReturn<T, D>>;

我是ts菜鸟,也许可以解决?

Alternative

No response

Additional context

No response

Validations

@KeJunMao KeJunMao added the enhancement New feature or request label Sep 15, 2022
@KeJunMao
Copy link
Author

@azaleta 谢谢你,可以的话,都加了个 D 了,能再加个范型 E 用于给error指定类型吗

@azaleta
Copy link
Contributor

azaleta commented Sep 24, 2022

#2248
I don't think it is E
it shoud be D

@sxzz
Copy link
Member

sxzz commented Sep 24, 2022

Fixed via #2248

@sxzz sxzz closed this as completed Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants